Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MYSQL update a DATE and TIME field in db manually

I am trying to figure out how to update a MYSQL DATE and TIME field manually (NOT to todays date!)ie set it the date field to a certain date value and time field to a certain time field correctly in the correct SQL required field format.

I am using an UPDATE query not INSERT as my action is to update a users field

Done some research and came up with something along the lines of (obviously this example wont work but does anyone know how to format this query?

UPDATE mytblname SET date='DATE: Manual Date', '2011-06-14'', time='TIME: Manual Time', '12:10:00' WHERE email='somevalue'

If I just enter the value as normal SQL way it gives 0000-00-00 for date and 00:00:00 for time - ie

SET date='2011-06-14',time='12:33:35'

Thanks for any suggestions, really appreciate it!!!

like image 505
daza166 Avatar asked Jul 07 '11 20:07

daza166


People also ask

How can I set current date and time in column in MySQL?

To insert only date value, use curdate() in MySQL. With that, if you want to get the entire datetime, then you can use now() method. Insert both date and time with the help of now().

How do I insert date in YYYY MM DD format in MySQL?

You can use str_to_date to convert a date string to MySQL's internal date format for inserting.


1 Answers

UPDATE mytblname SET `date`="2011-06-14", `time`="12:10:00" WHERE email="somevalue";

This should work fine. Make sure you have the appropriate backticks around date and time.

like image 71
Brad Avatar answered Nov 12 '22 15:11

Brad