Display today’s date on dashboard using javascript

1. Add any box container or the icon that will display the date

Image

 

2. Next right click and select ‘Data source’

Image

 

In the connection drop down, select ‘Personal Cloud’ and in the SQL enter the following SQL

select 'dummy' as Today

3. In the javascript window add this following code

Image

 


//get today's date into the variable

var today = new Date();

/* our SQL will return one data element containing the value "dummy"
in the glb array at the first position determined by [0][0]
so we simply replace the data value with our javascript date value */

glb["_json"]["data"][0][0]=today.toString();

4. Click OK

And you will see that the date is formatted in the default javascript format and displayed as below

Image

If you need to display the date in different format then you can use the date functions

For e.g if you just need to display the date part and don’t need the timezone and time part then you can achieve this as below.


glb["_json"]["data"][0][0]=today.getFullYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();

Image

SQL Method

Now the above method relied on the javascript to generate the date. But if you work with database then all SQL database provide a date function that you can use to display the current date.

For MySQL, you would use the now() function

select now() as "Today"

For Oracle

select sysdate as "Today' from dual

So find the appropriate database date/time function to display the dates on the dashboard.