Jump to content

Recommended Posts

I have a form that has this:

 

<input type="text" name="notes_date" size="10" value="<?php echo date("m/d/Y");?>" />

 

I enter into the database after processing the variable like this:

$notes_date=date ("Y-m-d H:i:s", strtotime($_POST['notes_date']));

However, it gets stored at 2012-03-15 00:00:00

 

How do I fix this so that the current time gets stored instead of 00:00:00?

 

Link to comment
https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/
Share on other sites

you can't, no time information is included with the date in the form, so it's not available when you are manipulating it with php for your date input.  The only three ways I can think of off the top of my head would be :

1:- include time information in the form,

2:- remove the date input from the form and calculate your date time as strtotime(date())

3:- remove the date input from your form and change the database field to a timestamp with default value of CURRENT_TIMESTAMP() and/or ON UPDATE CURRENT_TIMESTAMP()

I don't know, I have never tried to ALTER TABLE to swap in a timestamp field (don't even know if it would be possible because of the nature of the field), I've always either used it from the start or not at all.  You would be better asking in the MySQL forum for that info.

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.