getdate() function

This question already has an answer here:

  • How to return only the Date from a SQL Server DateTime datatype 37 answers

  • Use convert. The first argument truncates the length, and the last specifies the format you want the date in:

    SELECT Convert(varchar(10), getdate(), 103) as [Today's Date]
    

    If you are using SQL Server 2012+, you may also want to look at FORMAT - which in my opinion is a bit nicer to read/use.

    Example: SELECT FORMAT(GETDATE(), 'dd/MM/yyyy')

    See this msdn link for more info

    链接地址: http://www.djcxy.com/p/94378.html

    上一篇: 在sql server中仅从日期数据类型提取日期

    下一篇: getdate()函数