Format Date in InfoTemplate

1790
5
09-16-2010 07:48 AM
BenSayers
New Contributor II
Hello,
I am trying to get a date from a column in my attribute table for a feature layer, yet I can only get a number version, does anyone know how I can easily convert this into a proper date? Or retrieve a date in the first place?

This is what I am doing:
var wellContent = "<b>Well Name</b>: ${NAME}<br><b>Spud Date</b>: ${SPUD}";

This is an example of what I am getting returned:
636249600000

When the date in the attribute table is:
01/03/1990

Any ideas?
5 Replies
PatKeegan
Occasional Contributor
Having the same issue....were you able to solve this?
0 Kudos
KellyHutchins
Esri Frequent Contributor
At 2.2 we are making some changes to simplify this process but for now here's a sample that shows how to format the contents of an info window. This sample formats string values but could be modified to format numeric or date values.

http://help.arcgis.com/EN/webapi/jav...nfowindow.html

For date formatting you can use dojo.date.locale.format, the 'Page through records in a table' sample uses this to format date values:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/fl_paging.html
0 Kudos
PatKeegan
Occasional Contributor
Thanks Kelly,

The 1st link did not work and I was not able to determine which example you were referencing.

Also, I could not embed dojo.date.locale.format in the infoTemplate....any advice?

    infoTemplate = new esri.InfoTemplate();
    infoTemplate.setTitle("Information");
    infoTemplate.setContent("<b>Incident Type: </b>${IncidentCategory}<hr>"
  + "<b>Date: </b>${DATE_}<br/>"
  + "<b>Location: </b>${LOCATION}<br/>"
  + "<b>Description: </b>${PROBLEM}<br/>"
  + "<b>Incident ID: </b>${CASE__}"); 
    map.infoWindow.resize(245,125);
0 Kudos
KellyHutchins
Esri Frequent Contributor
The sample is in the Feature Layer folder and is called 'Format Info Window', here's the link again hopefully it'll work this time:

http://help.arcgis.com/EN/webapi/javascript/arcgis/demos/fl/fl_infowindow.html

You can't directly format the dates in the info window at this release, you have to listen for the layer's click event and format the contents of the info window there. At version 2.2 this will no longer be necessary.

 dojo.connect(featureLayer, 'onClick', function(e) {

          /*some of the values have a quote in the name - remove that then split the string

          to separate the common and scientific names. */

          var attr = e.graphic.attributes.qSpecies.replace('"', "").split("::");

          //if the common name isn't included display the scientific name instead. 

          var commonName = dojo.string.trim((attr[1] === "") ? attr[0] : attr[1]);

          //wikipedia uses the genus_species so build that value to append to wikipedia url 

          var scientificName = dojo.string.substitute("${0}_${1}", attr[0].split(" "));

          

          //populate the info window

          map.infoWindow.setTitle(e.graphic.attributes.qAddress);

          map.infoWindow.setContent("<b>" + commonName + "</b><br /><a target='_blank' href=http://en.wikipedia.org/wiki/" + scientificName + ">Wikipedia Entry</a>");

          map.infoWindow.show(e.screenPoint, map.getInfoWindowAnchor(e.screenPoint));

        });


0 Kudos
DanMcCoy
Occasional Contributor III
Kelly,

There's some help associated with the new date format functionality available since 2.2
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_formatinfowindow.htm

... but what's not clear is whether or not a feature layer is required (rather than just a ArcGISDynamicMapServiceLayer).  All of the samples I've found that use the new formating options reference feature layers.

I have a bunch of old code that uses querytasks/graphics to display the attributes in the infowindow which has been broken since the REST date/time format changed at AGS 10.  I've tried udating my JSAPI version to 2.7, and adding the formating info (i.e. "${EVENT_DATE:DateString}", "${EVENT_DATE:DateFormat}", etc.) with no luck.  I'm wondering if I need to recode everything to use feature layers to get the date working again...?

Thanks,

Dan
0 Kudos