2

I want to convert any date time (not current) format into unix timestamp. $dateToConvert = "2018-12-11 01:00:00"

input: $dateToConvert output: 1544490000 (value that i got from converter)

will be really thankful for help!

0

1 Answer 1

4

You would need to convert the $dateToConvert to a [DateTime] object before messing with it in PowerShell. You can then change the format of it to seconds by using the -UFormat parameter.

[datetime]$dateToConvert  = "2018-12-11 01:00:00"
Get-Date -Date $dateToConvert  -UFormat %s

More information regarding changing the format of the Get-Date can be found on the MSDocs Site

EDIT:

As per comment, you can just do the below for the same result.

Get-Date -Date "2018-12-11 01:00:00" -UFormat %s
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the -UFormat hint, but note that you can pass the date/time string directly to Get-Date, which implicitly converts it to [datetime] (using the rules of the invariant culture, as with the cast).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.