Popup calendar appears one month ahead of DB value

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:

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!

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

Your solution works.

Cheers,
Chris

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

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