Initializing easy chart dates at startup

I am using the easy chart and want to be able to set the start and end dates. I have tried several methods but keep getting errors. I obviously do not understand how dates are being used or whether it is a java date or python date.

What are the type of dates returned for the following:
client currentdatetime (tag)
now()
date range control

I am using the chart is historical mode but the startup range is not working.

Spookily I’m stuck doing exactly the same thing but with the Popup Calendar. Its ‘date’ property is in the form “12/08/2008 00:00:00 +0100” but I can’t seem to set it in code.

I am getting more confused with each attempt! For testing, I added two labels:

Label 1 = now(0)
Label 2 = dateArithmetic(now(0), -8, “day”)

I then added two dynamic properties to the root container called initialDateStart and initialDateEnd, both are defined as dates.

initialDateStart = toDate(dateFormat(dateArithmetic(now(0), -8, “day”), “yyyy-MM-dd 00:00:00”))

initialDateEnd = toDate(dateFormat(now(0), “yyyy-MM-dd 00:00:00”))

If the dynamic properties are already defined as dates then why did I have to use “toDate”

FactoryPMI Date properties are, technically, instances of java.util.Date. Expression language functions that return dates (like now()) are the same Dates. Queries that return SQL DATETIME or TIMESTAMP column types become Dates. Python dates are something different.

[quote="TimE"]What are the type of dates returned for the following:
client currentdatetime (tag)
now()
date range control[/quote]

They are all the same - Dates.

Because otherwise you would have been trying to assign a String (the return type of dateFormat) to a Date, which isn't valid.

Carl,

Any pointers on how I can initialise the Popup Calendar to a specific date using Python?

It is by far easiest to initialize a popup calendar date using an expression or a polling-off query, but if you’re hell-bent on using scripting, its not too hard:

current time in python:

from java.util import Date datePopup = event.source.parent.getComponent("DatePopup") datePopup.date = Date()

More flexible date setting using java.util.Calendar:

[code]from java.util import Calendar
cal = Calendar.getInstance()

set(year, month, day_of_month, hour_of_day, minute)

cal.set(2008, 4, 23, 8, 0)
datePopup = event.source.parent.getComponent(“DatePopup”)
datePopup.date = cal.getTime()[/code]

Hope this helps,

Following on from this (bit of a delay I know :slight_smile: ) I want to get today’s date as a string for inclusion in an SQL Update statement. I’ve come up with the following code:

from java.util import Calendar today = Calendar.getInstance().getTime() from java.text import SimpleDateFormat todaysDate = SimpleDateFormat("yyyy-MM-dd").format(today) print todaysDate
Is this the most straightforward way of doing this?

Sure, looks good to me!

This system will have multiple users, so to guard against time on the view nodes being different, I thought it would be better to read all times and dates from the database server:

try: currentTime = fpmi.db.runScalarQuery("SELECT NOW() FROM myDatabase") from java.text import SimpleDateFormat dateAndTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentTime) print dateAndTime except: print "SQL error"