Page 1 of 2
How to format Data object received from REST database ?
Posted: Mon Oct 28, 2013 2:22 am
by Bahar Wadia
I am getting a data object that reads as
2013-10-29 00:00:00.000
I want to convert it to
2013-10-29
or any other logical date format.
I have tried the javascript function .toDateString(); and other, but non seem to work. What am I missing ?
Thanks
How to format Data object received from REST database ?
Posted: Mon Oct 28, 2013 4:25 am
by maxkatz
.toDateString() function works with Date() object https://developer.mozilla.org/en-US/d.... You will find other approaches to parsing a date with JavaScript.
How to format Data object received from REST database ?
Posted: Sat Nov 02, 2013 7:42 pm
by bahar.wadia
Sorry my mistake (typo). I am receiving a date type from the REST database. So why am I having problems converting the date type to a readable format ?
Thanks
How to format Data object received from REST database ?
Posted: Sun Nov 03, 2013 12:15 am
by maxkatz
Check the JavaScript docs or find some other examples. Most likely it doesn't work with the format you are passing.
How to format Data object received from REST database ?
Posted: Sun Nov 03, 2013 11:33 pm
by bahar.wadia
I have create a column in the Appery database with the type Date. I save a Date type to the field. When I get the Date type back, I want to format it using javascript.
What am I missing ?
How to format Data object received from REST database ?
Posted: Sun Nov 03, 2013 11:45 pm
by maxkatz
You are getting a string from the database, and the function you are trying to us requires a Date().
var d = "2013-10-29 00:00:00.000";
var d2 = new Date (d);
alert (d2.toDateString());
How to format Data object received from REST database ?
Posted: Mon Nov 04, 2013 12:38 am
by bahar.wadia
That did it !
Thank you so much for your help!
However, Why am I getting a string from the database, even though I have specified a Date type?
How to format Data object received from REST database ?
Posted: Mon Nov 04, 2013 4:10 pm
by Maryna Brodina
Hello! mongoDB stores data in a specific format, but service returns data in JSON-object which is represented as string values (here is a specification http://tools.ietf.org/html/rfc4627)
How to format Data object received from REST database ?
Posted: Tue Apr 01, 2014 9:50 pm
by Matt6607699
Is the .toDateString() still working to convert a date from a Database Rest service into a better viewable format? I am running the JS from the date label's "add JS" because it is in a grid loop.
I tried using the code above but it doesn't want to work.
How to format Data object received from REST database ?
Posted: Tue Apr 01, 2014 10:17 pm
by Matt6607699