# Request help with a date conversion

**URL:** <https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126>\
**Category:** Ignition\
**Created:** [January 11, 2021, 7:10pm UTC](https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126 "2021-01-11T19:10:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephyliniemi](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@josephyliniemi](https://forum.inductiveautomation.com/u/josephyliniemi)\
**Post date:** [January 11, 2021, 7:10pm UTC](https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126/1 "2021-01-11T19:10:33Z")

</div>

I am trying to use a given date, take that date and essentially create a serial code for the date. Everything works like I want it to with one exception.

Here is the code:

```auto
dRan = row[27] 
print dRan
date = str(dRan)
print date
inputFormat = SimpleDateFormat("MM/dd/yyyy HH:mm:ss a")
dateOut = SimpleDateFormat.parse(inputFormat,dRan)
print dateOut

```

The results are  
1/7/2021 7:47:22 PM  
1/7/2021 7:47:22 PM  
Thu Jan 07 07:47:22 CST 2021

this is causing the serial creation to be off from what it should be.  
Here is the complete coding for it:

```auto
dRan = row[27]
print dRan
date = str(dRan)
print date
inputFormat = SimpleDateFormat("MM/dd/yyyy HH:mm:ss a")
dateOut = SimpleDateFormat.parse(inputFormat,dRan)
print dateOut
year = system.date.format(dateOut, "YY")
DoY = system.date.format(dateOut, "DDD")
HtoS = int(system.date.format(dateOut, "HH"))*3600
MtoS = int(system.date.format(dateOut, "mm"))*60
SoD = int(system.date.format(dateOut, "ss"))
seconds = str(HtoS + MtoS + SoD).zfill(5)
f_name1 = year + DoY + seconds
print f_name1

```

The result of f\_name1 is:  
2100728042  
it should be  
2100771242

it seems that the format seems to ignore the ‘a’ for AM or PM and the time code is off by 12 hours.

I am not sure what I am doing wrong, any help will be greatly appreaciated.

---

<div class="post-metadata">

**Author:** ![CalebM](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CalebM](https://forum.inductiveautomation.com/u/CalebM)\
**Post date:** [January 11, 2021, 7:44pm UTC](https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126/2 "2021-01-11T19:44:09Z")

</div>

I got this to work by changing the H’s to lower case. Uppercase HH is used for 24 hour format. This should do the trick.

```auto
SimpleDateFormat("MM/dd/yyyy hh:mm:ss a")

```

---

<div class="post-metadata">

**Author:** ![josephyliniemi](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@josephyliniemi](https://forum.inductiveautomation.com/u/josephyliniemi)\
**Post date:** [January 11, 2021, 8:00pm UTC](https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126/3 "2021-01-11T20:00:33Z")

</div>

That did the trick, thank you very much for your help!!!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 11, 2021, 10:36pm UTC](https://forum.inductiveautomation.com/t/request-help-with-a-date-conversion/42126/4 "2021-01-11T22:36:53Z")

</div>

You can also use the [https://docs.inductiveautomation.com/display/DOC81/system.date.parse](https://docs.inductiveautomation.com/display/DOC81/system.date.parse) function to avoid the manual `SimpleDateFormat` import.
