Microseconds extraction

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

Post Reply
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Microseconds extraction

Post by vivekreddy »

Hi.

I have a BIGINT field of length 18 and containing data in format YYMMDDHHNNSSssssss, basically timestamp.
I need to split this field into two fields, one a date field YY-MM-DD, and time field HH:NN:SS.ssssss.
I am able to generate the date part properly by first converting the number to character using stage variable and then using the StringToDate method, but am unable to generate the time part with the microseconds using the StringToTime method.
To say more clearly, the time field generated is of format HH:NN:SS, and does not display the microseconds portion.

What should I do?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

What is the syntax you use to convert? Try %HH%NN%SS.xxxxxx.
Alternatively you can convert it into microseconds, and can use time_from_microseconds() function.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

kumar_s wrote:What is the syntax you use to convert? Try %HH%NN%SS.xxxxxx.
Alternatively you can convert it into microseconds, and can use time_from_microseconds() function.
I use the syntax for conversion as follows. This step is preceded by converting the BIGINT field value to character value.
StringToTime(((svToCharAccessID)[7,2]:":":(svToCharAccessID)[9,2]:":":((svToCharAccessID)[11,2]:".":(svToCharAccessID)[13,6])),"%hh:%nn:%ss.xxxxxx")

This isn't working. Also could u explain in a little more detail as to how I can use the time_from_microseconds() function?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

You dont need to concatenate with ":" and then mention the format as %HH:%MI... You can straight away give %hh%nn%ss.xxxxx.
The other method is convert all hh, nn, ss that you found using svToCharAccessID)[7,2]:":":(svToCharAccessID)[9,2],Sad(svToCharAccessID)[11,2],(svToCharAccessID)[13,6] to microsecond and then convert it back into time using the function.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

kumar_s wrote:You dont need to concatenate with ":" and then mention the format as %HH:%MI... You can straight away give %hh%nn%ss.xxxxx.
The other method is convert all hh, nn, ss that you found using svToCharAccessID)[7,2]:":":(svToCharAccessID)[9,2],Sad(svToCharAccessID)[11,2],(svToCharAccessID)[13,6] to microsecond and then convert it back into time using the function.
I am unable to understand how I can convert the string to Microsecond. Also, I have tried the first method that you suggested viz. explicitly giving the desired format without concatenation of special characters, and it isn't working.

Any other suggestions that I could try out?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Try mentioning the extension of micro seconds in the datatype of that field using field properties.
Converting seconds into micro second is by multiplying by 1000000 and adding with the microsecond part of the exisiting values. Converting minute into micro second would be 60*1000000 and so on...
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

kumar_s wrote:Try mentioning the extension of micro seconds in the datatype of that field using field properties.
Converting seconds into micro second is by multiplying by 1000000 and adding with the microsecond part of the exisiting values. Converting minute into micro second would be 60*1000000 and so on...
Although I have understood the part of conversion to microseconds, I don't understand how to convert the said thing back to the desired format, or rather to time, considering that I am unable to find the time_from_microseconds() function. I can only find the microseconds_from_time() function.
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Iam sorry I dont know where I got this from :oops: .
You should be looking at the format of the data type of that field with the other method.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

kumar_s wrote:Iam sorry I dont know where I got this from :oops: .
You should be looking at the format of the data type of that field with the other method.
Really no problem. You must be working with DataStage so much that you must have forgotten more than what you can remember. At least that way, I was compelled to go though the entire developer's guide to find out all and any information about microseconds conversion/extraction, which I found to be a educative, if not entirely rewarding experience.
The argument passed to the MicrosecondsFromTime() method is of data type Time, and it returns an int32 value as the microseconds. However, since the Time field itself is not returning the microseconds portion, I doubt that this would be of much help.

Could you suggest some other thing?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

I dont have access to PX now. I am expecting that there should be a option if you tweak the data type defaults of that field, which I already said.
BTW: Why do you need to convert it into Time data type, why can you keep as varchar as is.
Since many version including some earliar version of database use as Date and time.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

kumar_s wrote:I dont have access to PX now. I am expecting that there should be a option if you tweak the data type defaults of that field, which I already said.
BTW: Why do you need to convert it into Time data type, why can you keep as varchar as is.
Since many version including some earliar version of database use as Date and time.
System requirements dictate the conversion. Can't really help it.
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
Post Reply