SQL command to get the current date is the day of the week code Summary

Source: Internet
Author: User

1 "select datepart (weekday, getdate ())

This is the integer of the returned day of the week!

2 "select datename (weekday, getdate ())

This is more convenient. You can directly return the day of the week type. For example, if today is Tuesday, enter Tuesday.

Note: If the obtained Date Field is short integer, for example, the week may be incorrect!

3 "select a as week, getdate () as date
From (select a = 'monday', B = 1
Union all select 'tuesday', 2 Union all select 'wedday', 3
Union all select 'thurs', 4 union all select 'Friday', 5
Union all select 'saturday', 6 Union all select 'sunday', 0
) A Where B = (datepart (weekday, getdate ()-1)

This methodCodeA little more, but the corresponding functions can also be achieved!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.