Cov txheej txheem:

Dateadd rov qab los li cas?
Dateadd rov qab los li cas?

Video: Dateadd rov qab los li cas?

Video: Dateadd rov qab los li cas?
Video: SQL Tricks | How to Find First Day of Last Month ? EOMONTH | DATEADD 2024, Kaum ib hlis
Anonim

SQL Server DATEADD () ua haujlwm saib xyuas

Cov DATEADD () muaj nuj nqi ntxiv ib tug xov tooj mus rau ib tug teev hnub ib feem ntawm ib tug input hnub thiab rov qab los tus nqi hloov. Cov DATEADD () muaj nuj nqi lees txais peb qhov kev sib cav: date_part yog ib feem ntawm hnub uas lub DATEADD () ua haujlwm yuav ntxiv tus nqi.

Tsuas yog li ntawd, kuv yuav siv Dateadd li cas?

Yuav siv li cas DATEADD() Muaj nuj nqi thiab piv txwv

  1. Ntxiv 30 hnub rau hnub SELECT DATEADD(DD, 30, @Date)
  2. Ntxiv 3 teev rau hnub SELECT DATEADD(HOUR, -3, @Date)
  3. Tshem tawm 90 feeb los ntawm hnub SELECT DATEADD(MINUTE, -90, @Date)
  4. Mus saib daim ntawv qhia kom tau ib daim ntawv teev tag nrho cov kev xaiv.

Ib yam li ntawd, Getdate rov qab los hauv SQL li cas? TAU TXAIS () Piv txwv hauv SQL ntawv Server (T- SQL ntawv ) Cov TAU TXAIS () ua haujlwm rov qab los hnub tim thiab lub sij hawm tam sim no raws li tus nqi hnub tim. Tus nqi no yog muab los ntawm lub operating system ntawm lub computer uas qhov piv txwv ntawm SQL ntawv Server tab tom khiav.

Ib yam li ntawd, koj tuaj yeem nug, Dab tsi yog kev siv Dateadd hauv SQL Server?

DATEADD () Piv txwv hauv SQL Server . Hauv SQL Server , koj ua tau siv tus DATEADD () ua haujlwm ntxiv rau lub sijhawm teev tseg rau hnub tim. Koj tuaj yeem ua tau siv nws yuav rho tawm lub sijhawm teev tseg. Koj kuj tuaj yeem ua ke DATEADD () nrog rau lwm lub luag haujlwm los teeb tsa hnub raws li xav tau.

Kuv yuav ntxiv xyoo rau hnub hauv SQL li cas?

xaiv getdate () +10 tab sis tsis ua haujlwm. Xaiv DATEADD( Xyoo , 10, TAU TXAIS ()) yuav ua li no ntxiv 10 Xyoo mus rau hnub tam sim no. Ntxiv mus, Cov Lus Nug koj tau muab I.e SELECT GETDATE () + 10 yuav ntxiv 10 Hnub rau hnub tam sim no.

Pom zoo: