2

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?

Jan Kovařík
  • 1,542
  • 1
  • 11
  • 18
  • I think your question the same as this question: http://stackoverflow.com/questions/9847213/which-day-of-week-given-a-date-python – titipata Feb 20 '17 at 23:41
  • 1
    Possible duplicate of [which day of week given a date python](http://stackoverflow.com/questions/9847213/which-day-of-week-given-a-date-python) – TemporalWolf Feb 20 '17 at 23:46

3 Answers3

2

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

Community
  • 1
  • 1
titipata
  • 5,321
  • 3
  • 35
  • 59
2

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

Sarada Akurathi
  • 1,164
  • 7
  • 28
  • 56
0

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?

Community
  • 1
  • 1
Tony Dong
  • 3,213
  • 1
  • 29
  • 32