Jump to content

Getting time added with date


jeff5656

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
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()

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.