Cov txheej txheem:

Kuv tuaj yeem tau txais hnub tim li cas hauv dd mm yyyy hom hauv SQL?
Kuv tuaj yeem tau txais hnub tim li cas hauv dd mm yyyy hom hauv SQL?

Video: Kuv tuaj yeem tau txais hnub tim li cas hauv dd mm yyyy hom hauv SQL?

Video: Kuv tuaj yeem tau txais hnub tim li cas hauv dd mm yyyy hom hauv SQL?
Video: Data Science with Python! Extracting Metadata from Images 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 rau CONVERT muaj nuj nqi.
  2. Kom tau YYYY - MM-DD siv Xaiv CONVERT(varchar, getdate(), 23)
  3. Kom tau MM/DD / YYYY siv Xaiv CONVERT(varchar, getdate(), 1)
  4. Mus saib daim ntawv qhia kom tau ib daim ntawv teev tag nrho hom ntawv kev xaiv.

Hauv qhov no, kuv tuaj yeem tau txais hnub tim li cas hauv dd mm yyyy hom ntawv hauv SQL query?

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.

Qhov thib ob, Kuv yuav hloov hnub hom li cas 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.

Ntawm no, hom ntawv hnub twg hauv SQL yog dab tsi?

YYYY-MM-DD

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 lub Hloov pauv ua haujlwm rau hloov cov cim rau sql hnub.

Pom zoo: