Reputation: 2255
I wish to set the System.DateTime object below with the time from $time:
$CurrentTime = (date)
$Time = "9:00"
How do I get the date from $CurrentTime, but with hours, minutes, seconds from $time?
Upvotes: 2
Views: 16011
Reputation: 31
$CurrentTime = Get-Date -Hour "09" -Minute "00" -Second "00"
Upvotes: 1
Reputation: 4629
This should work:
$CurrentTime = [System.DateTime]::Parse((date).ToString("yyyy.MM.dd"))
$Time = [System.Timespan]::Parse("9:00")
$Result = $CurrentTime.Add($Time)
Upvotes: 1
Reputation: 126932
Get-Date -Year $CurrentTime.Year `
-Month $CurrentTime.Month `
-Day $CurrentTime.Day `
-Hour $time.split(':')[0] `
-Minute $time.split(':')[-1]
-Second $time.split(':')[-1]
Upvotes: 1