jeff5656 Posted March 15, 2012 Share Posted March 15, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/ Share on other sites More sharing options...
Muddy_Funster Posted March 15, 2012 Share Posted March 15, 2012 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() Quote Link to comment https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/#findComment-1327698 Share on other sites More sharing options...
jeff5656 Posted March 15, 2012 Author Share Posted March 15, 2012 I like option 3. If i change to timestamp, wiill that overwrite all the previous dates in the database records (because it was originally set as datetime)? Quote Link to comment https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/#findComment-1327699 Share on other sites More sharing options...
Muddy_Funster Posted March 15, 2012 Share Posted March 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/#findComment-1327704 Share on other sites More sharing options...
jeff5656 Posted March 15, 2012 Author Share Posted March 15, 2012 Changing to timestamp worked - the previous dates were not erased (but their times remain 00:00:00 of course, until they get updated) Quote Link to comment https://forums.phpfreaks.com/topic/258992-getting-time-added-with-date/#findComment-1327742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.