Free cookie consent management tool by TermsFeed Policy Generator
  • SQL Server
  •    1 page views
  •   0 video views
  • 2024, August 20, Tuesday

#064 Get and format the current date in Azure SQL

Como obter e formatar a data atual em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code uses the CONVERT function to format the current date in British-style date format (DD/MM/YYYY). I'll explain each part of the code:

SELECT 
  CONVERT(
    varchar,
    GETUTCDATE(),
    103
  ) AS Formatted Date
CONVERT(
  1. varchar, GETUTCDATE(), 103) AS FormattedDate:
    • CONVERT: Function used to convert one data type to another.
    • varchar: Indicates that the result of the conversion will be of type varchar (string).
    • GETUTCDATE(): Function that returns the current date and time in UTC (Coordinated Universal Time).
    • 103: This is a formatting style code for dates, and in this case, style 103 represents the British-style date format (DD/MM/YYYY).
    • AS-FormattedDate: Renames the conversion result to "FormattedDate".

Therefore, the code returns the current date and time formatted as a British-style string (DD/MM/YYYY). The result is stored in the "FormattedDate" column. This query is useful when you need to display the current date in a specific format.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 0 min 44 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now