Date to Timestamp

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date to Timestamp

Post by pavan_test »

Hello,

I have source where the date is coming in the format 04/05/2012

can somone please tell me how do I convert this date to timestamp.

Thanks
Pavan
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: Date to Timestamp

Post by SURA »

Which format are you expecting?

DS User
nbalegar
Participant
Posts: 9
Joined: Fri Jul 08, 2011 2:47 am

Re: Date to Timestamp

Post by nbalegar »

You can use DateToString() by specifying the format and again convert back the result to StringToTimestamp().
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

There is always the TimestampFromDateTime() transformer function
- james wiles


All generalizations are false, including this one - Mark Twain.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

First confirm for us the data type of this incoming 'date'... is it indeed a date or is it a string in that format? I suspect the latter as real dates have no 'format'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date To Timestamp

Post by pavan_test »

The incoming date format is : 04/05/2012

I wish to convert to Timestamp. (add zeros to the end is also fine)

Thanks
Pavan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry, but that does not answer my question at all.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date To Timestamp

Post by pavan_test »

The data type is date

Thanks
Pavan
mobashshar
Participant
Posts: 91
Joined: Wed Apr 20, 2005 7:59 pm
Location: U.S.

Post by mobashshar »

Use TimestampFromDateTime(ink_InputDate,"00:00:00")
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date To Timestamp

Post by pavan_test »

The data is coming in the form of a string not date. I apologize for my previous posting.

I tried with TimestampFromDateTime and it is not working.

APT_CombinedOperatorController(1),1: Data string '03/23/2012' does not match format '%yyyy-%mm-%dd': the value for tag %yyyy has fewer characters than expected.

Thanks
Pavan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

StringToTimestamp().
-craig

"You can never have too many knives" -- Logan Nine Fingers
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date To Timestamp

Post by pavan_test »

When I tried the StringToTimestamp, I am getting this error message,

APT_CombinedOperatorController(1),0: Data string '03/10/201200:00:00' does not match format '%yyyy-%mm-%dd %hh:%nn:%ss': the value for tag %yyyy has fewer characters than expected.

StringToTimestamp(DateToString(DSLink2.da,"%yyyy-%mm-%dd") : ' 00:00:00',"%yyyy-%mm-%dd %hh:%nn:%ss")


the data from the source is string and i find thi: 04/13/2012

Thanks
Pavan
Thanks
Pavan
mobashshar
Participant
Posts: 91
Joined: Wed Apr 20, 2005 7:59 pm
Location: U.S.

Post by mobashshar »

Use this

TimestampFromDateTime(StringToDate(lnk_Date.Date,"%mm/%dd/%yyyy"),"00:00:00")
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

So, what is the format of your incoming date string (using the format specifiers, not an actual date)? Does it match the format "%yyyy-%mm-%dd"?

TimestampFromDateTime() didn't work for you probably because you haven't converted your incoming string into a date datatype. DataStage attempted to do that for you, couldn't and clearly gave you the reason why in the error message.

DateToString() is inappropriate within your StringToTimestamp() call because you ALREADY have a string for the date...why do you feel the need to convert a string from a Date to a String?. You're almost there---concatenate your date and time strings together and provide the correct format to the function. Date/Time format strings have been <a href="http://publib.boulder.ibm.com/infocente ... umented</a> for years...a brief search in the product documentation and you can find it :)

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

Date To Timestamp

Post by pavan_test »

This works

TimestampFromDateTime(StringToDate(lnk_Date.Date,"%mm/%dd/%yyyy"),"00:00:00")

Thanks
Pavan
Post Reply