Write-Host "number of total days difference between the two dates is " $difference.TotalDays -ForegroundColor DarkYellow Write-Host "number of milliseconds difference between the two dates is " $difference.Milliseconds -ForegroundColor DarkYellow Write-Host "number of seconds difference between the two dates is " $difference.Seconds -ForegroundColor DarkYellow Write-Host "number of minutes difference between the two dates is " $difference.Minutes -ForegroundColor DarkYellow Write-Host "number of hours difference between the two dates is " $difference.Hours -ForegroundColor DarkYellow Write-Host "number of days difference between the two dates is " $difference.Days -ForegroundColor DarkYellow Write-Host "the value of a the first date after conversion is "$date2"and the type is" $date2.GetType() -ForegroundColor DarkYellow $date2=::ParseExact($stringb,'mm/dd/yyyy',$null) Write-Host "Converting the second string to date" -ForegroundColor DarkYellow Write-Host "the value of a the first date after conversion is "$date1 "and the type is" $date1.GetType() -ForegroundColor DarkYellow $date1=::ParseExact($stringa,'mm/dd/yyyy',$null) Write-Host "Converting the first string to date" -ForegroundColor DarkYellow Write-Host "The current data type of the objects is" $stringa.GetType() "and" $stringb.GetType() -ForegroundColor DarkYellow Write-Host "Demo about coverting strings into dates and finding difference" -ForegroundColor DarkYellow $testpattern = '\year yyyy an\d \da\te dd an\d \mon\t\h MMM an\d \ti\me H mm' $test = 'year 2020 and date 12 and month feb and time 9 00' Write-Host "Complex example of custome pattern" Write-Host "example of yymmddhhmm format" Write-Host "String to Date conversion examples" Write-Host "Date in year format" -ForegroundColor DarkYellow Write-Host "month day format" -ForegroundColor DarkYellow Write-Host "Date in general date time long format" -ForegroundColor DarkYellow Write-Host "Date in general date time short format" -ForegroundColor DarkYellow Write-Host "long date long time" -ForegroundColor DarkYellow Write-Host "long date short time" -ForegroundColor DarkYellow Write-Host "Date in long date format" -ForegroundColor DarkYellow Y or y: Denotes Year month pattern Examples of PowerShell Convert String to Dateīelow are the examples of PowerShell: Example #1 G: Denotes general data time short format The following are the various date formats available in PowerShell. Types of Date Format Available in PowerShellīefore learning about the various ways in which string can be converted to a data object, it is important to learn about various date types that are available in PowerShell. Write-Host "After conversion the type is" $string.GetType() "and the value is" $string $string=::ParseExact($string, 'MM/dd/yyyy', $null) Write-Host "The variable type now is" $string.GetType() Write-Host "Welcome to string to date conversion example"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |