convert dates in Unix time format
Hello all,
I have around 900 dates in the format of DD-MM-YYYY and I want to convert them in Unix time format...
Is there a way to do this? I was thinking of passing them into an array, and then, for each date, I would use the function date() I suppose and get the Unix time format of them... But I don't know the way to do it...
So, for instance, if you have:
$date_to_format='05-10-2006' , how would I get the Unix timestamp?
Thank you in advance!
Re: convert dates in Unix time format
You want to use either mktime or strtotime. Make time basically has a hour, minute, second, month, day year format. You'd have to split your date up using explode for example, and then pass in the parameters:
$dateArray=explode('-,$mydate);
$myTimestamp=mktime(0,0,0,$dateArray[1],$dateArray[0],$dateArray[2]);
http://us2.php.net/explode
http://us2.php.net/manual/en/function.mktime.php
Alternatively you could just see whether strtotime will just understand your date format and produce the timestamp:
http://us2.php.net/strtotime
Strtotime will produce a timestamp from almost anything, for example, strtotime("Last thursday"); but using different formats generates sometimes incorrect results. Always check that your timestamp has worked by then passing it into date:
date('d-m-Y',$myTimestamp);
Hope that helps.
Re: convert dates in Unix time format
If you are getting your dates from mysql database you can also try unixtimestamp(), a mysql's built function.
SELECT UNIXTIMESTAMP(d_date) as t_tmestamp FROm table