# dateFormat returning the wrong year

**URL:** <https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 30, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310 "2024-12-30T17:37:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billy\_Grigo](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@Billy\_Grigo](https://forum.inductiveautomation.com/u/Billy_Grigo)\
**Post date:** [December 30, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/1 "2024-12-30T17:37:32Z")

</div>

Hey all,

I hope your holidays have been going well!

Just looking for a quick sanity check and maybe some pointers regarding an expression that I'm using on a label component in perspective.

The specific function is:

```python
dateFormat(NOW(), "YYYY")

```

I'm having a very confusing time as it is currently returning 2025. This post was created at around 11:30AM on Dec. 30th 2024 local time. I've checked PC time settings, local PC time settings, and pretty much everything else I can think of anyways.

For reference, `now()` by itself seems to return the correct date and time, not 2025.

Any advice would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 30, 2024, 5:40pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/2 "2024-12-30T17:40:10Z")

</div>

Use lower case.

(Look closer at the pattern definitions.)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 30, 2024, 6:36pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/3 "2024-12-30T18:36:38Z")

</div>

See [dateFormat | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time/dateFormat)

which references  
[https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html)

which gives,

| Letter | Date or Time Component | Presentation | Examples |
| --- | --- | --- | --- |
| `G` | Era designator | [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) | `AD` |
| `y` | Year | [Year](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#year) | `1996`; `96` |
| `M` | Month in year | [Month](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#month) | `July`; `Jul`; `07` |
| `w` | Week in year | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `27` |
| `W` | Week in month | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `2` |
| `D` | Day in year | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `189` |
| `d` | Day in month | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `10` |
| `F` | Day of week in month | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `2` |
| `E` | Day in week | [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) | `Tuesday`; `Tue` |
| `a` | Am/pm marker | [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) | `PM` |
| `H` | Hour in day (0-23) | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `0` |
| `k` | Hour in day (1-24) | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `24` |
| `K` | Hour in am/pm (0-11) | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `0` |
| `h` | Hour in am/pm (1-12) | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `12` |
| `m` | Minute in hour | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `30` |
| `s` | Second in minute | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `55` |
| `S` | Millisecond | [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) | `978` |
| `z` | Time zone | [General time zone](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#timezone) | `Pacific Standard Time`; `PST`; `GMT-08:00` |
| `Z` | Time zone | [RFC 822 time zone](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#rfc822timezone) | `-0800` |

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 30, 2024, 6:40pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/4 "2024-12-30T18:40:13Z")

</div>

That old table doesn't show the difference between upper and lower case `y`. This one is more current:

[https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 30, 2024, 7:14pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/5 "2024-12-30T19:14:06Z")

</div>

Submitted to [docs@inductiveautomation.com](mailto:docs@inductiveautomation.com).

---

<div class="post-metadata">

**Author:** ![Billy\_Grigo](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@Billy\_Grigo](https://forum.inductiveautomation.com/u/Billy_Grigo)\
**Post date:** [December 30, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/6 "2024-12-30T20:20:32Z")

</div>

Thanks for the replies Phil and Transistor, lowercase did solve my problem.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 30, 2024, 8:45pm UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/7 "2024-12-30T20:45:45Z")

</div>

Just to round this off a bit, `YYYY` returns the "week year", or the year that a week belongs to. (As far as I can make out) Week 1 contains the 1st January and since that's a Wednesday in 2025 the preceeding Monday and Tuesday are also in Week 1 of 2025. So (for my locale, Ireland), I get,  
`dateFormat(toDate("2024-12-29 08:00:00"), "YYYY")` → 2024  
`dateFormat(toDate("2024-12-30 08:00:00"), "YYYY")` → 2025  
`dateFormat(toDate("2024-12-31 08:00:00"), "YYYY")` → 2025  
`dateFormat(toDate("2025-01-01 08:00:00"), "YYYY")` → 2025

 ![YYYY year](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/c/ccdb612479fa70184d01f7d243d3cb0557bd8861.png)  
_Figure 1. Week 1 of 2025 contains the last two days of 2024, so the Week Year is 2025 for those two dates._

There's some discussion over on [StackOverflow](https://stackoverflow.com/a/56911450/3934992) which goes into some detail - but who has time?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 28, 2025, 8:54am UTC](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/8 "2025-03-28T08:54:54Z")

</div>

For anyone stumbling across this, see

> [@dateFormat returning the wrong year](https://forum.inductiveautomation.com/t/dateformat-returning-the-wrong-year/100310/3):
>
> See [dateFormat | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time/dateFormat) which references [https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html) which gives, Letter Date or Time Component Presentation Examples G Era designator [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) AD y Year [Year](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#year) 1996; 96 M Month in year [Month](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#month) July; Jul; 07 w Week in year [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) 27 W Week in month [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) 2 D Day in year [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) 189 d Day in month [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) 10 F Day of week in month [Number](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#number) 2 E Day in week [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) Tuesday; Tue a Am/pm marker [Text](https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html#text) PM H …

and the follow-on examples.
