How to get Day of Week

Best practices, code snippets for common functionality, examples, and guidelines.
kkaehler
Posts: 9
Joined: Wed Oct 04, 2017 3:33 pm
Location: Munich, Germany

How to get Day of Week

Post by kkaehler » Fri Jan 19, 2018 4:21 pm

Hi,

I'm using the following and it's working fine:
string datum = System.DateTime.Today.AddDays(1).ToString("dd.MM.yyyy");
inputtagInfo.FindAdapter<InputTag>().PressKeys(datum);

But my testcase needs a day in a normal working week, no saturday or sunday. So I can't let this start on a friday :oops:
I would like to know the day of the week, so I could in case of friday just add 3 days.
I intented with DayofWeek, but it didn't work.

Someone an idea? I would appreciate, thanks :)

Best,
Karin

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to get Day of Week

Post by krstcs » Fri Jan 19, 2018 4:34 pm

You could do this:

Code: Select all

string datum = System.DateTime.Today.AddDays((System.DateTime.Today.DayOfWeek == DayOfWeek.Friday ? 3 : 1)).ToString("dd.MM.yyyy");
Notice where I replaced "1" with "System.DateTime.Today.DayOfWeek == DayOfWeek.Friday ? 3 : 1". This says "if Today is Friday, return 3, if not, return 1".
Shortcuts usually aren't...

kkaehler
Posts: 9
Joined: Wed Oct 04, 2017 3:33 pm
Location: Munich, Germany

Re: How to get Day of Week

Post by kkaehler » Fri Jan 19, 2018 5:20 pm

It works absolutely great!!
Thanks :mrgreen:

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to get Day of Week

Post by krstcs » Mon Jan 22, 2018 3:01 pm

You're quite welcome! Glad it helped.
Shortcuts usually aren't...