MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Begining of Month TIMESTAMP

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Thu Apr 09, 2009 4:08 pm    Post subject: Begining of Month TIMESTAMP Reply with quote

I have query that will produce the first time stamp for the current month. Is it possible to get the same results without so many functions?

Code:
select CURRENT timestamp -
 (select DAY(CURRENT DATE)
         FROM SYSIBM.SYSDUMMY1)days + 1 days  -
         (select hour(CURRENT time)
         FROM SYSIBM.SYSDUMMY1)hour -
           (select minute(CURRENT time)
         FROM SYSIBM.SYSDUMMY1)minute -
            (select second(CURRENT time)
         FROM SYSIBM.SYSDUMMY1)second     -       
              (select microsecond(CURRENT timestamp)
         FROM SYSIBM.SYSDUMMY1)microsecond
  FROM SYSIBM.SYSDUMMY1; 

Returns:
2009-04-01 00:00:00.000000




_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Thu Apr 09, 2009 4:39 pm    Post subject: Reply with quote

NASCAR9,

isnt it simple like this? You can use TIMESTAMP(Date,TIME) function to get the desired results.

To get the first of the current month ,take the current date and subtract a month from and use LAST_DAY function to get the last day of prior month and then add 1 day to it which would give you the first day of the current month.

Code:

SELECT TIMESTAMP(LAST_DAY(CURRENT DATE - 1 MONTH) + 1 DAY,       
                 TIME('00:00:00'))                               
 FROM SYSIBM.SYSDUMMY1;                                           


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Thu Apr 09, 2009 4:42 pm    Post subject: Reply with quote

NASCAR9,

You can even use DAYOFMONTH function to get the first day of the month
Code:

SELECT TIMESTAMP(CURRENT DATE - DAYOFMONTH(CURRENT DATE) DAYS + 1 DAY,
                 TIME('00:00:00'))                                   
 FROM SYSIBM.SYSDUMMY1;                                               


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Thu Apr 09, 2009 4:47 pm    Post subject: Reply with quote

kolusu, I guess I just used a backhoe when I only needed a shovel. Thanks!
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group