Learn ASP about date Operations SQL statement Summary

Source: Internet
Author: User
Tags date time and date
sql| Date | statement

List data for one day, last week

SELECT distinct DateAndTime
From Ctdate_by_query_date
WHERE DateAndTime between ((#2006 -5-15#+ (Weekday (2006-5-15) -7))-6) and (#2006 -5-15#-7) +weekday (2006-5-15)
Sql= "SELECT distinct dateandtime from ctarticle WHERE dateandtime between (#" &date& "#+ (Weekday (" &date & ")" &norp& "7)"-6) and (# "&date&" # "&norp&" 7) +weekday ("&date&") "

data for all days of the week being queried

SELECT *
From Ctdate_by_query_date
WHERE DateAndTime between ((#2006 -5-15#+weekday (2006-5-15))-6) and #2006 -5-15#+weekday (2006-5-15)

query a time period

SELECT *
From Ctdate_by_query_date
WHERE DateAndTime between #2006 -5-1# and #2006 -5-30#

list years of different years, and do not have the same

SELECT distinct year (dateandtime) from ctarticle
Results such as:
Expr1000
2000
2003
2004
2005
2006

List one day, the first record of the previous year

SELECT top 1 DateAndTime from ctarticle where year (dateandtime) = (2006)-1
Sql= "SELECT top 1 dateandtime from ctarticle where year (dateandtime) = (Year (# &date&" #) "&norp

list data for a particular year

Sql= "SELECT * from Ctdate_by_query_date where year (dateandtime) =" &year (rqqdt_) & "ORDER BY dateandtime Desc"

find the first record in the previous month

SELECT top 1 DateAndTime from ctarticle where year (dateandtime) =year (#2006 -5-28#) and month (DateAndTime) =month (# 2006-5-28#)-1

list data for a January

Sql= "SELECT * from Ctdate_by_query_date where year (dateandtime) =" &year (rqqdt_) & "and month (dateandtime) =" &month (rqqdt_) & "ORDER BY dateandtime Desc"

list data for one day

Sql= "SELECT * from Ctdate_by_query_date where dateandtime=#" &rqqdt_& "# ORDER BY A.articleid Desc"

Time and date

Example one: List the data for the day
Sql= "SELECT * from Ctdate_by_query_date where dateandtime=date () Order BY A.articleid Desc"



Related Article

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.