View Full Version : Daft date question
10-16-2009, 05:26 PM
I know this is probably a stupid question but I can't get my head around the date() and strtotime() functions in PHP.
How can I get the following date format into a Unix timestamp?
I.e. "18/07/2009 11:44:00" into a Unix timestamp? I've tried various combos and just can't get it to work!!
10-16-2009, 05:35 PM
Dates using a slash / as the separator must be in the U.S. mm/dd/yyyy format (sorry to all the countries that use dd/mm/yyyy) - http://www.gnu.org/software/tar/manual/html_node/Calendar-date-items.html#SEC116
You either need to use a different separator or break the date into its' separate pieces and put it back together or use the mktime() function.
Is there a good reason why you want to use a Unix Timestamp, given all the problems with using them for most purposes?
10-16-2009, 05:44 PM
echo strtotime(str_replace('/','-','18/07/2009 11:44:00'));
echo '<br/>'. strtotime('2009-07-18 11:44:00'); ?
10-16-2009, 05:53 PM
Funny that this topic just came up in another post...
Put this function in your script:
// Convert a date in this format: "18/07/2009 11:44:00"
// To a UNIX TimeString (eg. 1255624200)
// Separate the date from the time.
// Separate the month, day, year.
// Separate the Hour from Minute
// Generate a UNIX TimeStamp
And call it like this ...
$textdate = "18/07/2009 11:44:00";
$unixtime = DateToTimeStamp($textdate);
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.