Select to view content in your preferred language

Date Format: how to format date from geo-database?

810
4
Jump to solution
01-14-2013 08:45 AM
cristiBJ
Deactivated User
My code read "date" field and displays the date in a datagrid. It only shows numbers such as 1352935936000.

The database field for the data is
Status_Date ( type: esriFieldTypeDate , alias: Status_Date , editable: true , nullable: true , length: 36 )

I believe we need to convert the date somehow. Can anyone help?
0 Kudos
1 Solution

Accepted Solutions
cristiBJ
Deactivated User
Thank you jgravois, I did it.

In the grid, add the formatter function as below.

<th field="Request_Date" width="75px" formatter="formatDate">Request Date</th>

Then, add the conversion function.
function formatDate(value) {
          var inputDate = new Date(value);
          return dojo.date.locale.format(inputDate, {
              selector: 'date',
              datePattern: 'MM/dd/yyyy'
          });

      }

View solution in original post

0 Kudos
4 Replies
JohnGravois
Deactivated User
the dates need to be converted out of UTC.  check out the following article for more information
0 Kudos
ReneRubalcava
Esri Frequent Contributor
You'll want to create a date object from the data before displaying it.
So something like var d = new Date(1352935936000).
Then you can use d.toString() and format your date accordingly.
http://msdn.microsoft.com/en-us/library/ie/ff743760(v=vs.94).aspx

Dojo comes with dojo/date/locale that can help you format the dates as well.
http://dojotoolkit.org/reference-guide/1.8/dojo/date/locale/format.html
0 Kudos
cristiBJ
Deactivated User
Thank you jgravois, I did it.

In the grid, add the formatter function as below.

<th field="Request_Date" width="75px" formatter="formatDate">Request Date</th>

Then, add the conversion function.
function formatDate(value) {
          var inputDate = new Date(value);
          return dojo.date.locale.format(inputDate, {
              selector: 'date',
              datePattern: 'MM/dd/yyyy'
          });

      }
0 Kudos
JohnGravois
Deactivated User
glad to hear it 🙂
0 Kudos