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: 1275
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 How to force a select query to abend neo4u DB2 2 Mon Apr 23, 2018 1:36 pm
No new posts Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm
No new posts Need Guidance regarding UPDATE query Poha Eater DB2 3 Mon Feb 12, 2018 11:35 pm
No new posts Query to skip Max time-stamp and fetc... vickey_dw DB2 8 Sun Jan 28, 2018 1:09 am

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