Date Basics
taijidude

taijidude @taijidude

About: Java Developer. Love to read and learn. Hobbies: - tabletop rpgs - boardgames - videogames - cooking - kettlebell

Location:
Hannover, Germany
Joined:
Jul 22, 2020

Date Basics

Publish Date: Dec 22 '20
1 0

Short post before Christmas:

Calling Get-Date gives you a DateTime Object to work with:

(Get-Date).GetType()
Enter fullscreen mode Exit fullscreen mode

Alt Text

It is also possible to call Get-Date with a specific date string.

Get-Date "01.01.1970"
Enter fullscreen mode Exit fullscreen mode

To get a Date later than my specified date use the methods starting with Add.

Alt Text

To get the Date a week from today simple type the following:

(Get-Date).addDays(7).toString("dd.MM.yyyy")
Enter fullscreen mode Exit fullscreen mode

Alt Text

To get the Date a week prior from today i need to use the addDays() method with a parameter of -7.

(Get-Date).addDays(-7).toString("dd.MM.yyyy")
Enter fullscreen mode Exit fullscreen mode

Alt Text

How the date is printed into the shell you can control with the parameter value for the toString() Methode as seen in the two examples above.

If you want to check which day of the week the DateTime Object is set to, you can use the DayOfWeek Member.

(Get-Date).DayOfWeek
Enter fullscreen mode Exit fullscreen mode

Alt Text

Comments 0 total

    Add comment