ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to Change the Hour,Min, Sec Values in TimeStamp

Post new topic  Reply to topic
 How to Change the Hour,Min, Sec Values in TimeStamp « View previous topic :: View next topic » 
Author Message
arunkumar1989
PostPosted: Tue Jan 13, 2015 3:14 am    Post subject: How to Change the Hour,Min, Sec Values in TimeStamp Reply with quote

Voyager

Joined: 21 Nov 2012
Posts: 98
Location: Chennai

Hi all,

How to change the Hour,Min,Sec values in TimeStamp.

Ex : If we taken as CURRENT_TIMESTAMP

it will display the current date and time

In that i need to change time HH:mm:ss as 00:00:00
_________________
Being in a crowd when you are alone is ignorance. Enlightenment is being alone in a crowd; a feeling of oneness in a crowd.
Back to top
View user's profile Send private message Send e-mail
smdavies99
PostPosted: Tue Jan 13, 2015 3:44 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

A TIMESTAMP fiels is just that. A binary represtnation of a date time.

It has no format.

What you do is cast that binary represtantion into a character field using a cast statement.

for example

Code:

 declare tTimeNow TIMESTAMP CURRENT_TIMESTAMP;
 declare cTime Char;

 set cTime = cast(tTimeNow as char format 'yyyy-MM-dd HH:mm:ss';


The various options for the format string are fully documented in the InfoCentre.

you can go the other way as well.
Code:

 declare tTimeStamp TIMESTAMP;
 declare cTime Char '2014-12-31 23:59:59';

 set tTimeStamp = cast(cTime as timestamp format 'yyyy-MM-dd HH:mm:ss';


Try it out for yourself.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
arunkumar1989
PostPosted: Tue Jan 13, 2015 7:04 am    Post subject: Reply with quote

Voyager

Joined: 21 Nov 2012
Posts: 98
Location: Chennai

Thanks smdavies99... I have done this with SUBSTRING


Code:

SET ClubOpenTime1=CAST(CURRENT_TIMESTAMP AS CHARACTER);
      SET ClubOpenTime1=SUBSTRING(ClubOpenTime1 FROM 12 FOR 10);
      SET ClubOpenTime1=ClubOpenTime1 || ' 00:00:00';
      SET ClubOpenTime   = CAST(ClubOpenTime1 AS TIMESTAMP);   

_________________
Being in a crowd when you are alone is ignorance. Enlightenment is being alone in a crowd; a feeling of oneness in a crowd.
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Tue Jan 13, 2015 7:36 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

arunkumar1989 wrote:
Thanks smdavies99... I have done this with SUBSTRING


Code:

SET ClubOpenTime1=CAST(CURRENT_TIMESTAMP AS CHARACTER);
      SET ClubOpenTime1=SUBSTRING(ClubOpenTime1 FROM 12 FOR 10);
      SET ClubOpenTime1=ClubOpenTime1 || ' 00:00:00';
      SET ClubOpenTime   = CAST(ClubOpenTime1 AS TIMESTAMP);   


That's an incredible waste of time. You can accomplish everything you're doing with substring by using a format string on the CAST

And the end result is still a timestamp, which has no format. So you've cast things to an unformatted string, maniuplated that string to have the format you want, and then you've cast it back to an unformatted data type.

Dates and Times HAVE NO FORMAT.


Last edited by mqjeff on Tue Jan 13, 2015 8:49 am; edited 1 time in total
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 13, 2015 8:47 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

[quote="mqjeff"]That's an incredible waste of time. You can accomplish everything you're doing with substring by using a format string on the CAST
mqjeff wrote:
cially as string manipulation is one of the most expensive operations in ESQL.

[quote="mqjeff"]And the end result is still a timestamp, which has no format. So you've cast things to an unformatted string, maniuplated that string to have the format you want, and then you've cast it back to an unformatted data type.

Dates and Times HAVE NO FORMAT.




If you want a timestamp value of the current date at midnight, it's much more efficient to modify the timestamp directly without doglegging into CHARACTER and back.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to Change the Hour,Min, Sec Values in TimeStamp
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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.