Jump to content

[SOLVED] strtotime function is messing up


reece_1989

Recommended Posts

Ive got a slight problem that ive been trying to fix for hours and have NO idea at all ??

 

as you know the mysql db store dates yyyy-mm-dd

so ive modified my php coding so it enters dates in the db correctly etc.

 

BUT if the date is 0000-00-00 (i.e. nothing entered) then my site displays random old dates ??? :wtf:

 

my temp solution was using an if statment so if date = 0000-00-00 then display "" (nothing).

 

problem is when someone uses my update form and doesnt enter anything for date then a random date is put in the db (and then we dont know whther this is real or not) ?? im so stuck!

 

--what ive done so far: ---

when displaying dates on my site i want them in UK time

so i convert them to time:

<? 
$time = strtotime($date); 
?> 

 

and then to show on page:

echo "$time

 

this works fine!

 

 

when using an update form in php user enter date in UK format then i convert to time then yyyy-mm-dd -this enters dates into the db perfectly.

 

I dont have a clue :(  :facewall:

 

Thanks :)  ps. sorry its so confusing but its quite early in the morning :)

Link to comment
Share on other sites

You should set the mysql date field as a NULL field. If a date isn't entered into your form then your sql should insert NULL, not an empty value (SET dateField=NULL). You are correct all dates should be in the format of YYYY-MM-DD. When outputting the date you should check for a value first

if($row['dateField']) {
$row['dateField'] = date("d-m-Y", strtotime($row['dateField']));
}
print $row['dateField'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.