Alteryx designer Discussions

SOLVED

Date conversion to Day of Week

Highlighted
8 - Asteroid

Trying to convert a date to day of the week. So field of actual date to new variable that is Monday, Tuesday, Wednesday, etc... based on the field date. Have tried DateTimeParse and DateTimeFormat functions in Formula Tool - no luck!

This is a basic excel command????

Thanks

Highlighted
ACE Emeritus

Hi @BarleyCorn,

Check out the list of DateTimeFormats here: https://help.alteryx.com/9.5/index.htm#Reference/DateTimeFunctions.htm

From there, you can find the correct format to apply:

`DateTimeFormat([DateField],"%A")`

Highlighted
8 - Asteroid

Thanks John,

Worked, but also stung by Alteryx default on double and string!!

Highlighted
5 - Atom

I'm looking for a formula to return the Friday of a due date.  I want the actual date.

I'm considering using a long nested if statement such that: (syntax to be corrected)

if DateTimeFormat([DueDate],"%A") = "Sat" add 6 days

if DateTimeFormat([DueDate],"%A") = "Sun" add 5 days

if DateTimeFormat([DueDate],"%A") = "Mon" add 4 days

if DateTimeFormat([DueDate],"%A") = "Tue" add 3 days

if DateTimeFormat([DueDate],"%A") = "Wed" add 2 days

if DateTimeFormat([DueDate],"%A") = "Thu" add 1 days

if DateTimeFormat([DueDate],"%A") = "Fri" add 0 days

Elsewhere I've used a WeekDay formula to return the day of week as a number, then math into the Friday.  For example:

DueDate - WeekDay(DueDate) + 7 ... always returns the Friday date.

ACE Emeritus

Good idea.  The following would be a nice one-liner similar to yours:

`DateTimeAdd([DateField],5-ToNumber(DateTimeFormat([DateField],"%w")),"days")`

Highlighted
5 - Atom

I think you meant `%a` not `%A` --

%a = "Mon", "Tue", etc.

%A = "Monday", "Tuesday", etc.

Both work, but the former makes sense in the context of your conditionals.

Highlighted
5 - Atom

I didn't find anything on Alteryx's website about this, but I stumbled upon a possible solution.  DateTimeFormat([DateField],"%u") will give you the day of the week where Monday = 1 and Sunday = 7.

Highlighted
8 - Asteroid

@danejensen wrote:

I didn't find anything on Alteryx's website about this, but I stumbled upon a possible solution.  DateTimeFormat([DateField],"%u") will give you the day of the week where Monday = 1 and Sunday = 7.

This NEEDS to be in the documentation!

Thanks @danejensen !

Highlighted
5 - Atom

Thanks, @danejensen! This seems to work well. I have used ToNumber(DateTimeFormat([DateField],"%u")) to convert the field into number

Highlighted
7 - Meteor