Timestamp to week day in String (mon, tue)

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
srao
Premium Member
Premium Member
Posts: 41
Joined: Mon Mar 19, 2007 12:42 pm

Timestamp to week day in String (mon, tue)

Post by srao »

i tried below function but I am still getting the week day as number,(1, 2,etc) but i need to get weekday as MON, TUE, WEd etc.

I Used the TimestampToString() function to change to string and then did the Code:

FIELD(date, "-", 2, 1)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You do NOT require a string, because the weekday name is not part of a timestamp.

You need to extract the date part from the timestamp, then the weekday number from the date, then the weekday name from the weekday number, as I described the last time this question was posted.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You should have just stayed in your original thread. No reason to start a new one and break the relationship, one to the other.

Are you trying to follow Ray's advice there? What was your exact TimestampToString function used? The FIELD function just returns a portion of a delimited string and was meant to be used in conjunction with a 'day of the week' number determined earlier. Specifically -

If you know that 1 = Sunday, 2 = Monday, 3 = Tuesday, etc then use the field function more like:

Code: Select all

FIELD('SUN,MON,TUE,WED,THU,FRI,SAT',',',DayNumber,1)
Where DayNumber is the value determined ealier.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

... except that day number is zero-based (what isn't?)

So you will need a slight adjustment on Craig's Field() function. You can decide which day is the first in the week, which will cause the list of day name abbreviations to be different, appropriate to your locale.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
srao
Premium Member
Premium Member
Posts: 41
Joined: Mon Mar 19, 2007 12:42 pm

Post by srao »

Thanks for your help. I used the following but still getting weekday number (that is also not right, repeating the same numbers 1,2,3 for any date value). I think I am missing something. Please correct me.

FIELD('SUN,MON,TUE,WED,THU,FRI,SAT',',', WeekdayFromDate(TimestampToDate(INVENTORY_TIMESTAMP)) ,1)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Should not INVENTORY_TIMESTAMP be qualified with the input link name?

Try it a piece at a time.
Does TimestampToDate() work?
Then does applying WeekdayFromDate() work applied to that result?
Only then apply the Field() function.

Put the results into stage variables; put them on separate output columns while testing. You can simply eliminate these columns once you've got it working.

You may also need to add 1 to the third argument of Field(), since WeekdayFromDate() returns a zero-based count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply