Representing Jun, 2009 in php strtotime().

  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

hello,
is there a consistent way of representing the following string for example Jun, 2009 in php to a consistent timestamp so that the resulting timestamp can be consistent even days to come or even earlier days? using strtotime() or any other means in php. thanks...
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Read http://www.php.net/strtotime

Which will lead you to http://www.php.net/date_default_timezone_get

Which will introduce you to working with timezones in PHP and lead you to http://www.php.net/date_default_timezone_set

Which will explain how to set the timezone being used for date/time functions

Which will make what I'm about to say easier to understand.

Set the timezone to GMT/UTC before parsing the date to get a consistent time stamp.

If that doesn't help, I have no idea whatsoever what you mean when you say consistent. :)
  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

consisten i mean, the resulting int values i get, keep changing day by day and i don't need it to change since it's the same string am passing to the function. otherwise, let me have a look at the links you've given and i'll keep you posted thanks.. :|
  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

am afraid that didn't help me, though i learnt alot. i have this kinds of strings for example from mysql "May, 2009". now if even after setting my timezone to "Africa/Nairobi" before using strtotime() i keep getting different results if i adjust my local windows time... any suggestions?

Code: [ Select ]
 
date_default_timezone_set('Africa/Nairobi');
$date="May, 2009";
echo strtotime($date);
 
  1.  
  2. date_default_timezone_set('Africa/Nairobi');
  3. $date="May, 2009";
  4. echo strtotime($date);
  5.  
:(
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Bah, I forgot to click the submit button with my second reply yesterday.

Basically what's happening is "month, year" doesn't specify an exact date so it just fills in the blanks with the current time.

If you plan on getting only that format it might be easier to get the timestamp by parsing that string into month/year and using gmmktime().
  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

thanks big bro,
that's the function i needed. thanks for the link. :D

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.