# Popup calendar appears one month ahead of DB value

**URL:** <https://forum.inductiveautomation.com/t/popup-calendar-appears-one-month-ahead-of-db-value/9708>\
**Category:** Ignition\
**Created:** [February 13, 2015, 8:04pm UTC](https://forum.inductiveautomation.com/t/popup-calendar-appears-one-month-ahead-of-db-value/9708 "2015-02-13T20:04:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmoon](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dmoon](https://forum.inductiveautomation.com/u/dmoon)\
**Post date:** [February 13, 2015, 8:04pm UTC](https://forum.inductiveautomation.com/t/popup-calendar-appears-one-month-ahead-of-db-value/9708/1 "2015-02-13T20:04:44Z")

</div>

Like many other components, I wanted to easily bind my popup calendar to a database value (SQL DATETIME), set polling to Off, and have it write a new value back if changed by the user.

It took awhile to figure out how to write to the popup calendar correctly in the first place:

`
#data holds resultset from query		
date = data.getValueAt(0,"Pickup_date")
cal = Calendar.getInstance()
cal.set(int(date[:4]),int(date[5:7]),int(date[8:10]),0,0)
event.source.parent.getComponent('fldPickupDate').date = cal.getTime()
print "Date: "+date
print "Cal: "+str(cal.getTime())`

Gives me:

`
Date: 2015-08-09
Cal: Wed Sep 09 00:00:26 EDT 2015`

I can do a subtraction easily enough:

```auto
cal.add(2,-1)
```

… and that works, but I’d love to understand the discrepancy in the first place!

I know I’m missing something dumb. Help!

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [February 13, 2015, 9:41pm UTC](https://forum.inductiveautomation.com/t/popup-calendar-appears-one-month-ahead-of-db-value/9708/2 "2015-02-13T21:41:29Z")

</div>

The reason it is happening is because java calendar uses a 0 based index for months. 0 == January.

Your solution works.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![dmoon](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dmoon](https://forum.inductiveautomation.com/u/dmoon)\
**Post date:** [February 15, 2015, 3:52am UTC](https://forum.inductiveautomation.com/t/popup-calendar-appears-one-month-ahead-of-db-value/9708/3 "2015-02-15T03:52:09Z")

</div>

Thanks! That was more obvious than I would have thought.

Also, kudos for using the proper operator (==) in your reply. 😉
