SQL - update now () data with date only

I have an SQL database with a field that is populated with the now () function.

I want to update the current data only part of the date.

Example:

Existing data:

 20.08.2015 13:10:31
 21.08.2015 14:00:29
 22.08.2015 05:55:42

purpose

20.08.2015 
21.08.2015
22.08.2015

thank,

+4
source share
2 answers

Assuming you are using a MySQL database, you can use the date function

update yourtable
set yourColumnName = date(yourColumnName)

In SQL Server, try using the Convert Function

update yourtable
set yourColumnName =CONVERT(date, yourColumnName)

or

update yourtable
set yourColumnName CONVERT(varchar(10),yourColumnName,104)

otherwise you can use a function LEFTlike

update yourtable
set yourColumnName =LEFT (yourColumnName, 10)

SQL FIDDLE

+1
source

Assuming the data is in a table, you should do something like:

update t
    set col = cast(col as date);

. :

  • ()
  • date_trunc ('', col)
  • TRUNC (COL)
0

Source: https://habr.com/ru/post/1627956/


All Articles