Select to view content in your preferred language

problems retrieving correct datetime value from SDE/SQL Server

2764
2
06-24-2014 03:01 AM
JustinClowes
Emerging Contributor
I'm using the ArcGIS Server JS API to store a new feature using ApplyEdits.
The feature is created sucessfully. One of the feature attributes is a datetime field.

The field value is defined like this:

dt = new Date(2014, 6, 24, 10, 32);
fieldvalue = dt.valueOf();

The time of 10:32 goes into the database as 1402997520000 (the primitive value)

In the SQL Server database the time reads 10:32

When I retrieve the datetime value using the JS API the primitive value is 1402997519999, which displays as : 10:31.5999

Where am I going wrong?
0 Kudos
2 Replies
RaymondGoins
Regular Contributor
What is the fieldtype in the database? Date, Number... also what type of database MsSQL, Oracle, MySQL... I am assuming it is MSSQL Server but don't want to assume.

You would have to format the date before you insert it into the database. Other than 3 extra zeros at the end, that value looks like a unix timestamp.

Let me know the field type and can advise further.

Ray
0 Kudos
ManishkumarPatel
Deactivated User
Hi Justin,

The date value you mentioned is epoch time,which is defined as the number of seconds since midnight (UTC) on 1st January 1970.

What is epoch time?
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the  number of seconds that have elapsed since January 1, 1970 (midnight  UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).  Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but  'epoch' is often used as a synonym for 'Unix time'. Many Unix systems  store epoch dates as a signed 32-bit integer, which might cause problems  on January 19, 2038 (known as the Year 2038 problem or Y2038). 

Human readable time     Seconds
1 hour    3600 seconds
1 day    86400 seconds
1 week    604800 seconds
1 month (30.44 days)     2629743 seconds
1 year (365.24 days)      31556926 seconds


Although when you are retrieving the value and want to display in your application you will have to convert it using the below:

var someDate = new Date(dateString);

http://jsfiddle.net/patelmanya/Yz8Lv/

Hope this helps.

Best Regards,
Manish Patel
0 Kudos