toto
toto

Reputation: 71

How can I retrieve the day of the week from date

I need to retrieve the day of the week from the date. For example: 10/01/2017 corresponds to Tuesday. I'm using Robot Framework in which I can integrate javascript or python langage. Any help please?

Upvotes: 2

Views: 3035

Answers (3)

Sarada Akurathi
Sarada Akurathi

Reputation: 1188

you can directly use Robot Framework DateTime library here.

if you want the day as abbrivated (Mon, Tue, Wed ..etc) use the below format

*** Settings ***
Library   DateTime
*** TestCases ***
Date Convertion 
       [Arguments] ${Date}
       ${Day}=    Convert Date    ${Date}    result_format=%a
       [Return]   ${Day}

if want the day in full name format (Monday, Tuesday, ..etc) you should use the below format

${Day}=    Convert Date    ${Date}    result_format=%A

Both, I verified they are working fine, getting the proper result.

Hope this will solve your problem

Upvotes: 2

titipata
titipata

Reputation: 5389

In Python, you can use weekday in order to parse the date number.

from dateutil import parser
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
days_of_week = parser.parse('10/01/2017 ', dayfirst=True).weekday()
print(days[days_of_week])

note that dayfirst here is to say that first element in datetime that you put in is day instead of month

See more on which day of week given a date python as mentioned in comment by TemporalWolf

Upvotes: 2

Tony Dong
Tony Dong

Reputation: 3313

In javascript, you can do extend date object:

Date.prototype.getWeekDay = function() {
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
return weekday[this.getDay()];
}

you can call date.getWeekDay();

See more on How to get the day of week and the month of the year?

Upvotes: 0

Related Questions