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: 1243
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Want to pull the job log into a Mainf... Jishu Mukherjee Compuware & Other Tools 9 Tue Mar 21, 2017 4:48 pm

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