|
-
February 11th, 2007, 05:06 AM
#1
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!
-
February 11th, 2007, 06:49 AM
#2
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.
Last edited by Nibinaear; February 11th, 2007 at 06:53 AM.
-
February 15th, 2007, 10:54 AM
#3
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
All consequences are eternal in some way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|