0

Hi, I have the following code:

$date = 'Nov 7, 2007';
echo date('Y-m-d', strtotime($date));//outputs 2007-11-07

$date2 = $dates[1][0];
echo $date2;//outputs Nov 7, 2007
echo date('Y-m-d', strtotime($date2));//outputs 1969-12-31

How can I have the last line output 2007-11-07?

Thanks in advance.

2
Contributors
2
Replies
6
Views
9 Years
Discussion Span
Last Post by rogelioz
0

Hi rogelioz,

I've tried the code you posted and found that $dates[1][0] is not set. That is why you are getting a wierd date. I manually set the $date2 variable to 'Nov 7, 2007' and got the correct results.

<?php

$date = 'Nov 7, 2007';
echo date('Y-m-d', strtotime($date));

//$date2 = $dates[1][0];
echo $date2 = 'Nov 7, 2007';
echo date('Y-m-d', strtotime($date2));

?>

Check the code that sets the $dates[1][0] variable or post it for us to check out.

0

Hi, the problem was that $date2 had:

<td nowrap="nowrap" style="width:1%;">

Nov 7, 2007
</td>

Thanks for answering.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.