Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1224
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us