Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Query to pull dates using SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
sant532

New User


Joined: 02 Jun 2008
Posts: 48
Location: India

PostPosted: Thu Nov 13, 2008 8:30 pm    Post subject: Query to pull dates using SQL
Reply with quote

Hi all,
can any one suggest me a way to write a single query to pull
1. This month last date,
2. This month first date,
3. Next month first date,
4. Next month last date,
5. Previous month first date,
6. Previous month last date,
7. Last year first date,
8. Last year last date,
9. Next year first date,
10. Next year last date.

Thanks in advance.
Back to top
View user's profile Send private message

Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1258
Location: Israel

PostPosted: Thu Nov 13, 2008 9:51 pm    Post subject:
Reply with quote

1. This month last date: LAST_DAY(CURRENT DATE)
2. This month first date: LAST_DAY(CURRENT DATE - 1 MONTH) + 1 DAY
3. Next month first date: LAST_DAY(CURRENT DATE) + 1 DAY
4. Next month last date: LAST_DAY(CURRENT DATE + 1 MONTH)
...
7. Last year first date: DATE(CONCAT('01.01.',CHAR(YEAR(CURRENT DATE)-1)))
...
10. Next year last date: DATE(CONCAT('31.12.',CHAR(YEAR(CURRENT DATE)+1)))

you will have to fill the missing answers by yourself, it should be easy now...
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Nov 14, 2008 12:31 am    Post subject:
Reply with quote

Sounds like a class assigment. Marso I hope you get credit for the answer.
Back to top
View user's profile Send private message
sant532

New User


Joined: 02 Jun 2008
Posts: 48
Location: India

PostPosted: Fri Nov 14, 2008 12:05 pm    Post subject: Thanks...
Reply with quote

Thanks A lot Marso!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Comparing dates in different formats migusd SYNCSORT 4 Sat Nov 18, 2017 3:02 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us