We are updating the requirements for Community registration. As of 7/21/21 all users will be required to register a phone number with their My Alteryx accounts. If you have already registered, you will be prompted on your next login to add your phone number.
alteryx Community

# Alteryx Designer Discussions

SOLVED

## Date conversion to Day of Week

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

13 REPLIES 13
15 - Aurora

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")`

8 - Asteroid

Thanks John,

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

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.

15 - Aurora

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

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

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.

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.

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 !

5 - Atom

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

7 - Meteor