# formt txt to convert format dates and compare

**URL:** <https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726>\
**Category:** Pester\
**Created:** [May 30, 2018, 12:28pm UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726 "2018-05-30T12:28:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fred91120](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fred91120](https://forums.powershell.org/u/fred91120)\
**Post date:** [May 30, 2018, 12:28pm UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726/1 "2018-05-30T12:28:03Z")

</div>

Hello,

I want to retrieve the warranty dates of my DELL server devices and compare them to the current date, then my powershell script send the result to my CENTREON (less than 90 days Warning, less than 30 days CRITICAL…etc …)

I found a script “GetDellWarrantyInfo.ps1”  
here: [https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Script-Get-Dell-d7fd6367](https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Script-Get-Dell-d7fd6367)

the script works well and I get the information “warranty date” in a variable.

unfortunately I do not know how to process the information I get, I start powershell and I do not understand how to convert my result format date and then make the comparison with the date of the day.

Do you have some tips to bring me to help me in my research?

in advance a thank you to those who can help me.

Best regards

Fred

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 9, 2018, 9:03am UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726/2 "2018-06-09T09:03:16Z")

</div>

I’m not able to run the code as I don’t have a Dell, so I can’t see what data you’re actually getting back. If you could share some of that, it’d be easier to offer useful suggestions.

Generally, if you’re getting dates as a string, you want to convert them to a DateTime:

```
[DateTime]$datetime = "03/04/2018"
```

As an example. Get-Date also returns DateTimes:

```
$Now = Get-Date
```

And then you can compare using -gt (greater than) and -lt, or other comparison operators. Those all work against dates.

---

<div class="post-metadata">

**Author:** ![fred91120](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fred91120](https://forums.powershell.org/u/fred91120)\
**Post date:** [June 11, 2018, 2:42am UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726/3 "2018-06-11T02:42:33Z")

</div>

thank-s for your help 🙂

---

<div class="post-metadata">

**Author:** ![fred91120](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fred91120](https://forums.powershell.org/u/fred91120)\
**Post date:** [June 11, 2018, 2:46am UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726/4 "2018-06-11T02:46:25Z")

</div>

the script for

#===========================================================================================

# codes de sortie

# “OK” exit 0

# “WARN” exit 1

# “CRIT” exit 2

# “UNKNOW” exit 3

# version de powershell V3

# [https://www.microsoft.com/en-us/download/details.aspx?id=34595](https://www.microsoft.com/en-us/download/details.aspx?id=34595)

#Build URL

# “gwmi win32\_bios | Select –ExpandProperty SerialNumber”

$name = $args[1]

$servicetag = $args[0]  
$URL1 = “[https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/$ServiceTag](https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/$ServiceTag)”  
$URL2 = “?apikey=fe0cae32-xxxxx-49a6-a570-xxxxxae38401”  
$URL = $URL1 + $URL2

# Get Data

$Request = Invoke-RestMethod -URI $URL -Method GET -contenttype ‘Application/xml’

# Extract Warranty Info

$Warranty=$Request.AssetWarrantyDTO.AssetWarrantyResponse.AssetWarrantyResponse.AssetEntitlementData.AssetEntitlement|where ServiceLevelDescription -NE ‘Dell Digitial Delivery’

# Read first entry if available

If ($Warranty -is [Object])  
{  
$SLA=$Warranty[0].ServiceLevelDescription  
$EndDate=$Warranty[0].EndDate  
}  
else  
{  
$SLA=‘Expired’  
}  
$expiredate = $enddate.Substring(0,10)  
$lastdate = (Get-Date)  
$date = [System.datetime]$expiredate

$tdiff = New-TimeSpan -Start $lastdate -End $date  
$Nb\_jour = $tdiff.Days

IF( $Nb\_jour -gt “60” )  
{  
write-host -foregroundcolor green “$name , sous garantie pendant encore $NB\_jour jours , service TAG $servicetag” ;  
exit 0  
}

IF( $Nb\_jour -gt “0” )  
{  
write-host -foregroundcolor green “$name , sous garantie pendant encore $NB\_jour jours , service TAG $servicetag” ;  
exit 1  
}

write-host -foregroundcolor red “$name , hors garantie depuis $NB\_jour jours , service TAG $servicetag” ;  
exit 2

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:13pm UTC](https://forums.powershell.org/t/formt-txt-to-convert-format-dates-and-compare/10726/5 "2024-05-16T21:13:27Z")

</div>


