Jump to content

Recommended Posts

Hi i insert my dates from a calander into my mysql database with this:

 

$expireDate = date("Y-m-d", strtotime($_POST['expireDate']));

 

The client wants it displayed in the input box before being inserted in uk format d-m-Y.

 

If i do this using the above code the database doesnt understand it. I can display it after inserting it but how do i display it in the uk format before insert?

Link to comment
https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/
Share on other sites

There's a few things that need to all be done for this work optimally.

 

1) I'd suggest inserting your dates like so:

<?php
$expireDate = strtotime($_POST['expireDate']);
$query = "INSERT INTO some_table (expire) VALUES (FROM_UNIXTIME('$expireDate')";
?>

That way, you will always have it as the correct format inside the databsae.

 

2) When pulling the data, use the MySQL DATE_FORMAT() function.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

 

Once you have all that set up, I'd suggest making a timestamp of the date before displaying it.  Then, you can call the date() function when you display it, and use the timestamp in the value attribute of the expireDate field on your form.  If you do it this way, strtotime() is not needed on the receiving page.

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.