Page 1 of 1

Timestamp to week day in String (mon, tue)

Posted: Wed Apr 11, 2007 9:04 pm
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)

Posted: Wed Apr 11, 2007 9:32 pm
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.

Posted: Wed Apr 11, 2007 9:35 pm
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.

Posted: Wed Apr 11, 2007 9:45 pm
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.

Posted: Thu Apr 12, 2007 10:22 pm
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)

Posted: Fri Apr 13, 2007 1:54 am
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.