Cov txheej txheem:

Yuav ua li cas hloov ib hnub hom mus rau lwm hnub hauv SQL?
Yuav ua li cas hloov ib hnub hom mus rau lwm hnub hauv SQL?

Video: Yuav ua li cas hloov ib hnub hom mus rau lwm hnub hauv SQL?

Video: Yuav ua li cas hloov ib hnub hom mus rau lwm hnub hauv SQL?
Video: YUAV COJ LI CAS TU NEEG KOJ HLUB THIAJ NCO KOJ 2024, Kaum ib hlis
Anonim

Yuav ua li cas kom tau txais ntau hom SQL Server hnub tim

  1. Siv cov hnub format kev xaiv nrog Hloov pauv muaj nuj nqi.
  2. Kom tau YYYY-MM-DD siv SELECT CONVERT (varchar, getdate(), 23)
  3. Kom tau MM/DD/YYYY siv SELECT CONVERT (varchar, getdate(), 1 )
  4. Mus saib daim ntawv qhia kom tau a lis tag nrho hom ntawv kev xaiv.

Ua raws li qhov xav tau, kuv yuav ua li cas thiaj li tau txais hnub tim hauv YYYY MM DD hom hauv SQL?

Yuav ua li cas format SQL Server hnub nrog FORMAT muaj nuj nqi

  1. Siv FORMAT muaj nuj nqi los format hnub thiab sijhawm.
  2. Kom tau DD/MM/YYYY siv SELECT FORMAT (getdate(), 'dd/MM/yyyy ') raws li hnub tim.
  3. Kom tau MM-DD-YY siv SELECT FORMAT (getdate(), 'MM-dd-yy') raws li hnub tim.
  4. Tshawb xyuas cov piv txwv ntxiv hauv qab no.

Ib tug kuj yuav nug, hnub twg yog hom ntawv hauv SQL? SQL Server los nrog cov ntaub ntawv hauv qab no rau kev khaws cia hnub lossis hnub / sijhawm tus nqi hauv cov ntaub ntawv: DATE - hom ntawv YYYY-MM-DD . DATETIME - hom ntawv: YYYY-MM-DD HH:MI:SS . TSEEM CEEB - hom ntawv: YYYY-MM-DD HH:MI:SS.

Ib yam li ntawd, nws tau nug, peb puas tuaj yeem hloov varchar rau hnub tim hauv SQL?

Cov hloov dua siab tshiab ntawm a varchar hom ntaub ntawv rau a hnub tim hom ntaub ntawv ua rau muaj qhov tsis muaj nuj nqis. Koj xav tau cov separators rau cov hnub zoo li "/", "." los yog "-". Peb siv substring los concatenate lub "-" siv tau hnub format thiab ces peb siv cov Hloov pauv ua haujlwm rau hloov cov cim rau sql hnub.

Yuav ua li cas kuv hloov hnub tim hom hauv SQL Server Management Studio?

4 Teb. Koj ua tau hloov lub neej ntawd hnub format ib tus neeg siv los ntawm kev xaiv hom lus rau tus neeg siv ntawd hauv SQL Management Studio > Kev ruaj ntseg > ID nkag mus > {neeg siv khoom} > hom lus.

Pom zoo: