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.

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.

Hi, the problem was that $date2 had:

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

Nov 7, 2007
</td>

Thanks for answering.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.