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!!!
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().
You can use str_to_date to convert a date string to MySQL's internal date format for inserting.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With