0

I am trying to extract the day of the week from the AWS createdAt date format.

For example, given this date format: 2021-10-20T17:05:26.758Z find the day of the week (ie. Wednesday, Monday...)

I am working in Javascript and I am using AWS Amplify and Dynamo DB.

Tyler Morales
  • 1,440
  • 2
  • 19
  • 56

1 Answers1

1

This date 2021-10-20T17:05:26.758Z is a valid ISO 8601 date format, so you can use Date() and toLocaleDateString() to get day name:

const dayName = new Date('2021-10-20T17:05:26.758Z').toLocaleDateString('en-US', { weekday: 'long' });

console.log(dayName);
Zac
  • 1,497
  • 9
  • 11
  • 1
    Worth noting while the timestamp is UTC, this method returns the local day so while many will get Wednesday, anyone that is UTC +7 or greater will get Thursday. Also the "-US" subtag is redundant. :-) – RobG Oct 20 '21 at 23:45