Representing Jun, 2009 in php strtotime().

  • tiffix
  • Student
  • Student
  • User avatar
  • Joined: Jun 03, 2009
  • Posts: 65
  • Loc: kenya
  • Status: Offline

Post June 7th, 2009, 1:53 am

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...
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 7th, 2009, 1:53 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 7th, 2009, 2:11 am

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. :)
Strong with this one, the sudo is.
  • tiffix
  • Student
  • Student
  • User avatar
  • Joined: Jun 03, 2009
  • Posts: 65
  • Loc: kenya
  • Status: Offline

Post June 7th, 2009, 2:27 am

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
  • Joined: Jun 03, 2009
  • Posts: 65
  • Loc: kenya
  • Status: Offline

Post June 7th, 2009, 11:28 pm

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
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 8th, 2009, 12:16 am

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().
Strong with this one, the sudo is.
  • tiffix
  • Student
  • Student
  • User avatar
  • Joined: Jun 03, 2009
  • Posts: 65
  • Loc: kenya
  • Status: Offline

Post June 9th, 2009, 1:35 am

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 285 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.