Jump to content

[SOLVED] weird date format result


djsl

Recommended Posts

here is what I have

 

I am sending a timestamp using now to a table that is set to datetime through a form

 

this is the entry in the table  2009-08-20 09:47:11

 

I use this to echo in html and it shows up good

 

$notesline1date=mysql_result($result,$i,"notes_line_1_date"); 

$notesline1datenew = date('m j Y', strtotime($notesline1date));

 

<? echo $notesline9datenew; ?>

 

the problem I am having is when no date has been set the table is          0000-00-00 00:00:00

 

but the echo shows up as          11 30 -0001

 

I would like it to be blank, and is there a better way of doing this I am figuring things out as I go.

 

thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/
Share on other sites

$notesline1datenew = 'no date';
if (!is_empty_date($date)) {
    $notesline1datenew = date('m j Y', strtotime($notesline1date));
}

function is_empty_date($date) {
    return preg_match('/[0]{4}-[0]{2}-[0]{2} [0]{2}:[0]{2}:[0]{2}/', $date);
}

thanks for the help

 

I tried it and it works great, the only problem that I have now is that I have multiple lines of dates that I want to show

when I add the script to all the lines I get the following

 

 

Fatal error: Cannot redeclare is_empty_date() (previously declared in........

 

thanks

Fatal error: Cannot redeclare is_empty_date() (previously declared in.......

 

This error means that you have defined is_empty_date() multiple times, like:

 

function is_empty_date() ..

 

a few lines lower:

 

function is_empty_date() ..

 

Make sure function is_empty_date() only appears once.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.