I am trying to get the number of days difference in Windows powershell, I am extracting the last date of the year i.e.. 20171231(yyyyMMdd)
from a text file that I have locally stored the date in that file.
Here is the below code that I am trying but not able to get the difference of the days, am getting the wrong output by directly subtracting, if am converting the string extracted from the file and then subtract it with the date type, even then am getting the wrong output.
$DateStr = (Get-Date).ToString("yyyyMMdd")
$content = Get-Content C:\Users\Date.txt
$diff = $content.ToString();
#Convert it to the date type
$diff = [datetime]::parseexact($diff, 'yyyyMMdd', $null)
#$diff3 = $diff - $DateStr
According to the CDC, anyone who has a severe allergy (e.g., anaphylaxis) to any of the mRNA vaccine ingredients should not receive this vaccine. The CDC says people with allergies to certain foods, insects, latex and other common allergens can safely receive the COVID-19 vaccine.
Apply a clean, cool, wet washcloth to your arm to help reduce pain. It may also help to exercise your arm. If you have a fever, drink plenty of fluids and dress lightly. Over-the-counter medicines like Tylenol® (acetaminophen) or Motrin® or Advil® (ibuprofen) can help with pain, fever, headache, or discomfort.
Studies suggest that reinfection with SARS-CoV-2 with the same virus variant as the initial infection or reinfection with a different variant are both possible; early reinfection within 90 days of the initial infection can occur.
You should not take over-the-counter pain relievers such as aspirin, ibuprofen, or acetaminophen to help prevent side effects before you get the vaccine. It is not known if these medicines will affect how well the vaccine works.
Use New-TimeSpan
as it represents a time interval. Like so,
$d1 = '2017-01-01'
$d2 = '2017-05-01'
$ts = New-TimeSpan -Start $d1 -End $d2
$ts.Days # Check results
120
A quick, dirty, one line powershell script to get the difference between current date and any future date:
[math]::Ceiling((([DateTime]'mm-dd-yyyy')-(Get-Date)).TotalDays)
$DateStr is going to be a string, so it can't be parsed as a date. You can also use new-timespan to get the difference between two dates.
$Date = Get-Date
$diff = Get-Content C:\Users\Date.txt -raw
#Convert it to the date type
$diff = [datetime]::parseexact($diff, 'yyyyMMdd', $null)
$diff3 = New-TimeSpan -Start $diff -end $Date
#Number of days
$diff3.days
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With