SQL Exercise: Date Queries
SQL Date
Tutorial on Date query using DATE_SUB(), CURDATE()
SQL dump to use Date queries
Display all records of today's date
Display all records of yesterday
Display all records of tomorrow
Display all records of yesterday, today and tomorrow
Display all records of last 2 days ( no future dates )
Display all records of next 3 days ( no previous dates )
Display all records of Previous 10 days to previous 5 days
Display all records of next 5 days to next 10 days
Display all records of current month .
Display all records of current month and current year .
Display all records of previous month of current year
Display all records of Next month of current year
Display all records of previous, current and next month
Display all records of current month till today
Display all records of current year
Display all records of current week
Display all records of previous week
Display all records of Next week
Display all records of first week of the year
Display all records of working days ( Monday to Friday ) of current week of the year
Display all records of working days till today of current week of the year
Solution : can be used as SQL file
Video Tutorial on Date Query using CURDATE, BETWEEN , YEAR, MONTH, DAYOFWEEK()
VIDEO
More on Date
Use the 2nd part of the above SQL dump to work on the Months.
All records of present month
All records of last three months
All records within the range of last 2 and 4 months
Group by with Date field
Use this SQL DUMP to use group by queries applied on a date field .
Display Year and total number of payments done in that year
Display year ,total number of bills , sum of amount, average of amount against each year
Display month ,total number of bills , sum of amount, average of amount against each month
Modify Above query to show Year-Month in place of Year
Modify above query to show Year-Month-M1 and Year-Month-M2 format, here sale date from 1st to 15th of the month is M1 and from 16th to rest of the days of the month is M2
Display total number of bills, sum of amount, average of amount against each financial year. Financial year starts from 1st April and ends on 31st March. It is displayed as 2014-2015
Modify the above query to show Financial year starting from 1st October to 30th September
Financial year starting from 1st July to 30th June
Video Tutorial on GROUP BY on Date column Query
VIDEO
More on Date with Time
Use the 3rd part of the above SQL dump to work on Time.
SQL dump to use Date with Time queries
All records of last 24 hours ( including future records )
All records of last 24 hours till now.
All records from last 12 hours and 30 minutes
All records within the range of 13 to 14 hours ( lunch time )
All records within the range of 13 to 14 hours of one input day
All records between two input time in HOUR , Minute , Second
All records between two input time in HOUR , Minute , Second of a particular date
Number of records in each hour in all days
Number of records in each hour of a particular day
Number of records during Lunch hours ( from 13 to 14 hours ) on each day
Number of records during Lunch hours ( from 13 to 14 hours ) on a particular day
Find out the last record based on time for each day
Find out the first record based on time for each day
SQL Solution of Date with Time
Video Tutorial on NOW() with solutions
VIDEO
← Exercise on String, Update , delete Queries
← What is SQL
SELECT Query to collect records →
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com