Date formatting with PHP

Associate
Joined
29 Dec 2004
Posts
2,253
I'm trying to convert a list of dates from d/m/Y to Y-m-d, my list of dates are these so far:

30/09/2008
01/10/2008
02/10/2008
15/10/2008
22/10/2008
04/11/2008
12/11/2008
10/11/2008
04/11/2008
20/10/2008
14/11/2008

I'm using this code to convert it:

PHP:
$projectdate = date('Y-m-d', strtotime($projectdate));

But when i use this i get the following output:

1970-01-01
2008-01-10
2008-02-10
1970-01-01
1970-01-01
1970-01-01
1970-01-01
2008-04-11
2008-04-11
2008-10-11
2008-12-11
1970-01-01

Any ideas why this doesn't work?
 
short memory old chap. :p

from your other thread.....

i was hoping to read the dates simply by using strtotime() to convert the first 10 characters of each line into a unix timestamp. but it doesn't work with uk formatted dates.

edit:
i suppose you could do it using explode...

PHP:
$temp_array = explode('/', $projectdate);
$projectdate = $temp_array[2] . '-' . $temp_array[1] . '-' . $temp_array[0];
 
Last edited:
The problem looks like it's because the PHP function is expecting the dates your entering in american format.

How you change that, I don't know though.
 
PHP:
$temp_array = explode('/', $projectdate);
$projectdate = $temp_array[2] . '-' . $temp_array[1] . '-' . $temp_array[0];

Well i knew it was something not quite right with my date format. Your solution worked a treat and once again you are awesome etc...:D

Thankyou for being awesome.
 
Back
Top Bottom