Jump to content

timestamp problem


raymonn23

Recommended Posts

upon using PHP strtotime('2010-11-23 00:00:00') output a different values.

 

Asia/Taipei

int(1290441600)

 

Europe/London

int(1290470400)

 

Expected : Same since I declare the date that need to convert as timestamp

 

date_default_timezone_set('Asia/Taipei');
var_dump(strtotime('2010-11-23 00:00:00'));

date_default_timezone_set('Europe/London');
var_dump(strtotime('2010-11-23 00:00:00'));

 

Any explanation, Idea or alternative?

 

Please help. Thanks

 

Link to comment
Share on other sites

Does no one read the manual anymore?

 

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

 

So, if UTC is currently at 12:00:00 am and my local time is 5:00am and your local time is 7:00am, the timestamp returned by strtotime() would be exactly the same for both of us - since it is relative to UTC. If I waited until 7:00am my time to run strtotime() I woul dhave a timestamp that is 2 hours higher than the one you ran at 7am.

Link to comment
Share on other sites

Thanks mjdamato for the reply.

 

If that the case, any alternative that I can use to get the same value of

int representation of a date even the timezone is declared?

 

Ex.

date_default_timezone_set('Asia/Taipei');

echo function_ThatConvertDateToInt('2010-11-23 00:00:00');

 

date_default_timezone_set('Europe/London');

echo function_ThatConvertDateToInt('2010-11-23 00:00:00');

 

 

Sorry I'm just new with date to int

Link to comment
Share on other sites

Not sure what you are trying to achieve really. Why are you wanting to change the timezone setting at runtime for different regions in the same script?

 

As stated above, a timestamp is relative to UTC time. Is there some reason you need the date/time as a timestamp (i.e. in an integer format)? If not, just store the date/time as a string or a Date/Time value in the database, so it will not be relative to UTC.

Link to comment
Share on other sites

Thanks again for the reply mjdamato,

 

My problem is, we have an existing system and the timezone is set depends on user location.

I did an addons to that system with concerns of date.

 

ex.

user pick date : 11-24-2010

then

  *function_thatConvertDateToInt('11-24-2010')

  *Save to DB

 

But since strtotime() is base on now (your location / set timezone) I will get a different values,

so when I do SELECT WHERE date = (int date representation) I will get no return.

 

---------------

 

I'm thinking that I will set the timezone again depends on server location and by pass the automatic timezone settings but my codes will look bad.

ex.

//existing system timezone set to

date_default_timezone_set('Asia/Taipei');

//Set again timezone

date_default_timezone_set('Europe/London');

 

 

To summarize it :

I need a way that will convert date to int to its real value regardless of the timezone.

 

 

Ex.

date_default_timezone_set('Asia/Taipei');

echo function_ThatConvertDateToInt('2010-11-23 00:00:00');

 

date_default_timezone_set('Europe/London');

echo function_ThatConvertDateToInt('2010-11-23 00:00:00');

 

 

 

Link to comment
Share on other sites

Either I am not understanding you or you are making this more difficult than it needs to be.

 

You are apparently alble to convert the time entered by the user to the appropriate UTC timestamp. The whole point of using UTC is to ensure you are storing the time in a mormalized format. So, when you need to query the database, just offset the timestamps you use as needed for the local time of the server.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.