# Date format

**URL:** <https://forum.inductiveautomation.com/t/date-format/8211>\
**Category:** Ignition\
**Created:** [March 25, 2014, 4:20pm UTC](https://forum.inductiveautomation.com/t/date-format/8211 "2014-03-25T16:20:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![shv](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@shv](https://forum.inductiveautomation.com/u/shv)\
**Post date:** [March 25, 2014, 4:20pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/1 "2014-03-25T16:20:39Z")

</div>

Hello, is there a quick way to convert the date format “Mon Mar 03 4:14:39 CET 2014” to “2014-03-03 4:14:39”?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 25, 2014, 5:15pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/2 "2014-03-25T17:15:25Z")

</div>

Is this in a script? If so, Python will do it for you.

Check out [time.strptime](http://docs.python.org/2/library/time.html#time.strptime) to parse your string into a time struct, then [time.strftime](http://docs.python.org/2/library/time.html#time.strftime) to make it back into the string you want. (Don’t forget to import time.)

---

<div class="post-metadata">

**Author:** ![shv](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@shv](https://forum.inductiveautomation.com/u/shv)\
**Post date:** [March 26, 2014, 4:46pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/3 "2014-03-26T16:46:18Z")

</div>

Yes, it is. I’ve been doing some tests but with this script

`import time
res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")`  
the following error is displayed:

```auto
ValueError: time data did not match format: data=Wed Mar 26 10:13:54 CET 2014 fmt=%a %b %d %H:%M:%S %Z %Y
```

Any hints on what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [March 26, 2014, 5:26pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/4 "2014-03-26T17:26:36Z")

</div>

Which version of Ignition are you using? Try using the little “z” instead for the timezone.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 26, 2014, 5:47pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/5 "2014-03-26T17:47:48Z")

</div>

shv, I copied and pasted your code into a script, and it worked fine for me. (Gave me a value of (2014, 3, 26, 2, 13, 54, 2, 85, 1) )

The month and weekday names and abbreviations depend on your locale. What locale is your computer set up for? Your JVM?

---

<div class="post-metadata">

**Author:** ![shv](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@shv](https://forum.inductiveautomation.com/u/shv)\
**Post date:** [March 27, 2014, 10:14am UTC](https://forum.inductiveautomation.com/t/date-format/8211/6 "2014-03-27T10:14:49Z")

</div>

Kathy:

[quote]Timezone Europe/Madrid [GMT+1:00]  
Locale es\_ES[/quote]  
adamaustin: I tried using “% z” but has not solved the problem.

[quote]Ignition Version: 7.6.4 (b2013112117)  
Java Version: Sun Microsystems Inc. 1.6.0\_27[/quote]

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 27, 2014, 3:10pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/7 "2014-03-27T15:10:14Z")

</div>

You can also use java.text.SimpleDateFormat…

[code]from java.text import SimpleDateFormat

inputFormat=SimpleDateFormat(“EEE MMM dd HH:mm:ss Z yyyy”) # Must match the format of the input string  
outputFormat=SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”) # The format you want to convert to

dateIn=“Wed Mar 26 10:13:54 CET 2014” # Input Time/Date

processedDateIn=SimpleDateFormat.parse(inputFormat,dateIn) # Convert Input String to Java Date  
dateOut=outputFormat.format(processedDateIn) # Convert Java Date to a New String

print dateOut  
[/code]

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 27, 2014, 3:15pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/8 "2014-03-27T15:15:53Z")

</div>

I happen to have a vm set up in French, so I tried the script there. As expected, `res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")` fails, but `res = time.strptime("mer. mars 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")` works.

First, I would try altering your script to `import time
res = time.strptime("mié mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")
print res` and test it out.

If your data is arriving in English, you have a couple of choices. Assuming you are on a Windows machine, Python is looking at the settings under Control Panel \> Region and Language \> Formats \> Format for what the weekday and month abbreviations are. If you change that to English, Python will be happy with the English abbreviations, but your whole system will use English names and formats for any dates/times anywhere in the system – probably not what you want.

The alternative would be to set up a function that translates the abbreviations for you, using str.replace.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 27, 2014, 3:18pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/9 "2014-03-27T15:18:43Z")

</div>

Just a note: I tried Jordan’s solution in my French vm, and it fails when using English abbreviations, but works with French. I think that no matter what, the abbreviation is going to need to match what the OS thinks it should be for the locale.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 27, 2014, 3:30pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/10 "2014-03-27T15:30:32Z")

</div>

Okay, Using Kathy’s French date, I got it to work using a locale:

[code]from java.text import SimpleDateFormat  
from java.util import Locale

inputFormat=SimpleDateFormat(“EEE MMM dd HH:mm:ss Z yyyy”, Locale.FRENCH) # Must match the format of the input string  
outputFormat=SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”) # The format you want to convert to

dateIn=“mer. mars 26 10:13:54 CET 2014” # Input Time/Date

processedDateIn=SimpleDateFormat.parse(inputFormat,dateIn) # Convert to Java Date  
dateOut=outputFormat.format(processedDateIn) # Convert Java Date to String

print dateOut  
[/code]

So, try adding an English locale to the format string:

[code]from java.text import SimpleDateFormat  
from java.util import Locale

inputFormat=SimpleDateFormat(“EEE MMM dd HH:mm:ss Z yyyy”, Locale.ENGLISH) # Must match the format of the input string  
outputFormat=SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”) # The format you want to convert to

dateIn=“Wed. Mar 26 10:13:54 CET 2014” # Input Time/Date

processedDateIn=SimpleDateFormat.parse(inputFormat,dateIn) # Convert to Java Date  
dateOut=outputFormat.format(processedDateIn) # Convert Java Date to String

print dateOut  
[/code]

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 27, 2014, 3:37pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/11 "2014-03-27T15:37:30Z")

</div>

Ah, elegant! Much better than replacing strings.

I tried using Python’s locale to do the same thing. Let’s just say Python’s locale implementation isn’t ready for production work. 😃

[edit]  
As a side note, Java’s Locale class doesn’t have a constant for Spanish. (Silly, but nothing we can do.)

For a Spanish locale, replace Locale.FRENCH with new Locale(“es”, “ES”) (not sure if the capitalization is necessary.)

---

<div class="post-metadata">

**Author:** ![shv](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@shv](https://forum.inductiveautomation.com/u/shv)\
**Post date:** [March 27, 2014, 4:10pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/12 "2014-03-27T16:10:08Z")

</div>

It worked! Thank you very much guys. You have been very helpful.

Finally this solution is good for me.

[code]from java.text import SimpleDateFormat  
from java.util import Locale

inputFormat=SimpleDateFormat(“EEE MMM dd HH:mm:ss Z yyyy”, Locale.ENGLISH) # Must match the format of the input string  
outputFormat=SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”) # The format you want to convert to

dateIn=“Wed. Mar 26 10:13:54 CET 2014” # Input Time/Date

processedDateIn=SimpleDateFormat.parse(inputFormat,dateIn) # Convert to Java Date  
dateOut=outputFormat.format(processedDateIn) # Convert Java Date to String

print dateOut[/code]  
On the other hand I have no need to replace Locale.ENGLISH with new Locale (“es”, “ES”) because all dates are in English.

Regards

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 20, 2019, 6:14pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/13 "2019-05-20T18:14:54Z")

</div>

Kathy,  
Is there a way to generate a unique number out of it in Ignition before 7.7  
Like, generating it as 20140326 (yyyymmdd) out of the given date( Wed Mar 26 10:13:54 CET 2014)

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 20, 2019, 6:20pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/14 "2019-05-20T18:20:37Z")

</div>

Did you try using the techniques I suggested in March 2014 above?

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 20, 2019, 6:34pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/15 "2019-05-20T18:34:03Z")

</div>

> [@shv](#):
>
> `import time res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")`

Yes. It return the value 10, 3, 26, 0, 0, 0, 2, 85, -1, but cant make this as a number as it separated with ","

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 20, 2019, 7:22pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/16 "2019-05-20T19:22:27Z")

</div>

You can loop through the returned object and build a string from the values, or sum them, or whatever other method you would like to use.

```auto
import time 
res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")

sRes = ''
for i in range(len(res)):
	sRes += str(res[i])
	
print sRes

```

---

<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:** [May 20, 2019, 7:41pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/17 "2019-05-20T19:41:43Z")

</div>

```auto
import time 
res = time.strptime("2014/03/26 10:13:54", "%Y/%m/%d %H:%M:%S")
# the right answer:
print time.strftime("%Y%m%d%H%M%S", res)
# the lazy answer:
print ''.join(map(str, (r for r in res if r >= 0)))

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 20, 2019, 7:44pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/18 "2019-05-20T19:44:20Z")

</div>

You didn’t mention what version of Ignition you are running, but do you have _ **system.date.** _\* available to you?

```python
dateString = "Wed Mar 26 10:13:54 CET 2014"
format = "E MMM d HH:mm:ss z yyyy"

parsedDate = system.date.parse(dateString, format)

dateOut = system.date.format(parsedDate, 'yyyyMMdd')

```

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 21, 2019, 3:56pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/19 "2019-05-21T15:56:09Z")

</div>

Irose.  
Thanks and it works well. I am still playing with it to limit this length just enough to get YYYYMMDD. I don’t need time and time zone.  
I know Ignition 7.9, this was very easy to do and I have done with system.date syntax as Jordan said. But this is in 7.5, that is the trouble going through.

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 21, 2019, 4:22pm UTC](https://forum.inductiveautomation.com/t/date-format/8211/21 "2019-05-21T16:22:10Z")

</div>

Jordan,  
Sorry that I didnt mention the version. This one is 7.5 and as you said, this was easy to achieve in 7.9 with system.date format.  
Thanks again for your time and input. I really appreciate you all for the way being part of a query and response. It is an amazing forum and I hardly see these types of interactions with other group.  
Have a wonderful day.

[Next page](https://forum.inductiveautomation.com/t/date-format/8211.md?page=2)
