Jopekz Jopekz - 3 years ago 76
SQL Question

Update Date Part Only in Date Time SQL

I have a table that has a ReadingTimeStamp field (DateTime data type). As you can see in the picture. It has 2017-06-19 XX:XX:XX . I want to change only the date part (2017-06-19) to 2017-07-26 without affecting the time. Can someone help me with a query? I am using SQLite Studio. Please see attached file.

enter image description here

Answer Source

SQLite dates are basically just stored as strings. You can try the following update:

UPDATE yourTable
SET ReadingTimeStamp = '2017-07-26 ' || SUBSTR(ReadingTimeStamp, 12, 8)
WHERE SUBSTR(ReadingTimeStamp, 1, 10) = '2017-06-19'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download