VMware Cloud Community
fsosson
Contributor
Contributor
Jump to solution

Date from annotation comparison

Hi,

I have to compare today's date +15d with date read from VM annotation.

Here is the code for today + 15d:

$Date = Get-Date -format "dd/MM/yyyy"

$Date = [datetime]$Date

$inTwoWeeks = $Date.AddDays(15)

here the output: 16/06/2016 00:00:00

here the code to get date in annotation:

$expiryDate = $vm | Get-Annotation -CustomAttribute "MACHINE_EXPIRY_DATE"

$expiryDate = [string]$expiryDate

$expiryDate = $expiryDate.replace(" ","")

$expiryDate = $expiryDate.Trim("MACHINE_EXPIRY_DATE:")

here the output: 31/12/2014

My question, how can I convert the second output to make a comparison with the first output?

Regards,

Fred

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can use $expiryDate = Get-Date $expiryDate to convert $expiryDate into a datetime object that you can compare to $inTwoWeeks.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can use $expiryDate = Get-Date $expiryDate to convert $expiryDate into a datetime object that you can compare to $inTwoWeeks.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
fsosson
Contributor
Contributor
Jump to solution

Hi RvdNieuwendijk,

Thanks a lot, that fixed my issue.

Regards,

Fred

0 Kudos