# Julian Date

**URL:** <https://forum.inductiveautomation.com/t/julian-date/4851>\
**Category:** Ignition\
**Created:** [July 20, 2012, 1:32pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851 "2012-07-20T13:32:36Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [July 20, 2012, 1:32pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/1 "2012-07-20T13:32:36Z")

</div>

Is there a way to get the julian date through an expression, i.e. “dateExtract(now(),‘day’)”? I can get it through scripting, but in some cases it would be nice to have it as a bound dynamic property.

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [July 20, 2012, 3:25pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/2 "2012-07-20T15:25:51Z")

</div>

You can use dateDiff to find the number of days since the beginning of the year:

```auto
dateDiff(toDate("2012-1-1 0:00:00"), now(), "day")
```

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [July 20, 2012, 5:58pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/3 "2012-07-20T17:58:58Z")

</div>

Yes, but what happens next January? 🙂

I assume I’d have to create another expression that gets the current year, and pass the year indirectly into this expression?

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [July 20, 2012, 6:09pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/4 "2012-07-20T18:09:42Z")

</div>

try this out

[code]import datetime

now = datetime.datetime.now()

print “Current year: %d” % now.year[/code]

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [July 20, 2012, 6:12pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/5 "2012-07-20T18:12:37Z")

</div>

You can get the current year by calling dateExtract, and then using concat to attach that year to a string that has the other parts of the date that are static ("-1-1 0:00:00"). The final expression would look like this:

```auto
dateDiff(toDate(concat(toStr(dateExtract(now(),"year")),"-1-1 0:00:00")), now(), "day")
```

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [July 20, 2012, 6:18pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/6 "2012-07-20T18:18:31Z")

</div>

But that’s through scripting, and I’m already getting the date parts in other parts of the project with java.text.SimpleDateFormat. I saw in the expression docs that other date parts are available, so I  
thought maybe the Julian date was just undocumented.

edit: Sorry, was responding to the post above.

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [July 20, 2012, 6:25pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/7 "2012-07-20T18:25:29Z")

</div>

I posted an expression solution after Greg’s response.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [July 20, 2012, 6:37pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/8 "2012-07-20T18:37:36Z")

</div>

Yes, that should do it. Thanks James.

Just a question for my own curiousity- how efficient are expressions when it comes to execution times? Are they trivial compared to something like sql queries?

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [July 20, 2012, 9:47pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/9 "2012-07-20T21:47:56Z")

</div>

Expressions are more simple, the only thing that you might run into is that expressions will use more client processing power.

---

<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:** [July 20, 2012, 10:26pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/10 "2012-07-20T22:26:12Z")

</div>

Just wanted to add that datediff returns a float, so if you want the Julian day to be an integer then you would need to truncate the result to avoid rounding errors:

```auto
floor(dateDiff(toDate(concat(toStr(dateExtract(now(),"year")),"-1-1 0:00:00")), now(), "day"))
```

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [July 21, 2012, 1:56pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/11 "2012-07-21T13:56:48Z")

</div>

> [@Greg.Simpson](#):
>
> Expressions are more simple, the only thing that you might run into is that expressions will use more client processing power.

That was what I was getting to. How are expressions executed? Are they constantly updated on a seperate thread? What if, instead of an expression, I got the julian date through scripting like this (maybe on a timer):

```auto
from java.util import Calendar
import java.text.SimpleDateFormat as sdf
print sdf("DDD").format(Calendar.getInstance().getTimeInMillis())
```

Just curious as to which approach is more efficient assuming that I'm equally comfortable programming either.

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [July 22, 2012, 9:41am UTC](https://forum.inductiveautomation.com/t/julian-date/4851/12 "2012-07-22T09:41:08Z")

</div>

As I understand, expressions are typically more efficient than running on a timer because they fire when the window opens (InternalFrameActivate) and when their dependencies change, which typically isn’t often.

I’m not sure how frequently this expression would fire given the now() reference. Colby, Carl, Travis, Kevin - care to shed some light on this?

---

<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:** [July 23, 2012, 9:41am UTC](https://forum.inductiveautomation.com/t/julian-date/4851/13 "2012-07-23T09:41:41Z")

</div>

> [@Greg.Simpson](#):
>
> Expressions are more simple, the only thing that you might run into is that expressions will use more client processing power.

If (judging from the expressions we've been sharing in this thread) we're looking for the current Julian date, could this be bound to an SQLTag? I don't know if that would help the client by just referencing the tag vs. calculating it itself. On the other side, it would be calculated in one spot vs. everyone trying to do a redundant task.

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [July 24, 2012, 6:25pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/14 "2012-07-24T18:25:15Z")

</div>

Yes, the expressions can be bound to an expression tag, and then it can be reference from anywhere in any project within that gateway. As a general rule, expressions and property binding are better to use (if applicable) than scripting. It depends on the individual use case however. In this case, it depends on how many components are referencing that date, how precise/accurate the date needs to be, etc. However, if I understand what Step7 is using it for, an expression would be the most elegant and efficient way.

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://forum.inductiveautomation.com/u/ali)\
**Post date:** [May 27, 2021, 1:57pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/15 "2021-05-27T13:57:02Z")

</div>

solved this in Ignition 8 using the following code where %ty is the 2-digit year, and %tj is the 3-digit day of the year.

concat(  
stringFormat("%ty", now()),  
stringFormat("%tj", now())  
)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [December 15, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/16 "2021-12-15T16:32:25Z")

</div>

Does it handle leap years?

and also

does (dateFormat(now(),‘D’)) also handle leap years?

```auto
(dateFormat(now(),"D"))

```

quotes, not apostrophes

---

<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:** [December 15, 2021, 8:19pm UTC](https://forum.inductiveautomation.com/t/julian-date/4851/17 "2021-12-15T20:19:28Z")

</div>

Yes to both. 🙂

![Screenshot from 2021-12-15 15-12-12](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/eb5cb416a1ff9a735057286eb85356cca1295c88.png)

![Screenshot from 2021-12-15 15-11-50](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/23d51b05f312f03696d661eb1e2223b8edf618c1.png)
