Formatting date and time in powershell -


i want yesterday's date "mmdd" "0418"todays date is"0419" tried this:

$d=(get-date).adddays(-1)|select -property month,day $e=$d.day  $d=$d.month  $total="$d"+"$e"  write-host $total 

but output "418"

as can see 3 letter string want 4 letter one. because want search files have format , created day before.

the date object has method tostring, allows specify format:

$d = (get-date).adddays(-1); $d.tostring("mmdd"); 

i calling on april 20th, , output is

0419

see this link description of available date format strings.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -