Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL datetime update time to 00:00:00 from all other time values

Is there a way to update all columns in table from

2010-12-31 23:59:59.000

to

2010-12-31 00:00:00.000

Something like this??

UPDATE t1
SET [Posting Date] = [Posting Date] with ms = 00:00:00.000
WHERE ms = other than 00:00:00.000
GO
like image 399
AceAlfred Avatar asked Oct 24 '13 09:10

AceAlfred


People also ask

How can change time in datetime field in SQL query?

To update with the current date and time: UPDATE table_name SET date_field = CURRENT_TIMESTAMP; To update with a specific date value: UPDATE table_name SET date_field = 'YYYY-MM-DD HH:MM:SS.

What is DATETIME2 SQL?

Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.

What is datetime offset in SQL?

The SQL Server DateTimeOffset data type stores the date & time along with the Time Zone Offset. It is similar to both DateTime & DateTime2 data types. Except that the DateTime & DateTime2 does not store the Time Zone Offset.

How do I get the difference between two Datetimes in SQL?

To find the difference between dates, use the DATEDIFF(datepart, startdate, enddate) function. The datepart argument defines the part of the date/datetime in which you'd like to express the difference. Its value can be year , quarter , month , day , minute , etc.


1 Answers

UPDATE t1
SET [Posting Date] = cast([Posting Date] as date)
WHERE cast([Posting Date] as time) > '00:00'
like image 56
t-clausen.dk Avatar answered Nov 04 '22 01:11

t-clausen.dk