Convert datetime::Now value to specific format for comparison-Power Shell


Hi All,

How to convert datetime value to specific format for comparison

For get-date cmdlet, we have property called format , using that I can convert the date into specific format.

But for [datetime]::Now as it is c# static class, for that to convert the date time into specific format, you could use the toString method like below

$date = get-date -Format "yyyyMMddhhmm" – input value

$date2=([datetime]::Now).ToString("yyyyMMddhhmm") -comparing against time

if ( $date -eq $date2)

{

"yes"

}

else

{

"no"

}

Regards,

Chaitanya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: