Bahar Wadia
Posts: 0
Joined: Sat Oct 12, 2013 6:38 pm

How to format Data object received from REST database ?

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to format Data object received from REST database ?

.toDateString() function works with Date() object https://developer.mozilla.org/en-US/d.... You will find other approaches to parsing a date with JavaScript.

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

How to format Data object received from REST database ?

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to format Data object received from REST database ?

Check the JavaScript docs or find some other examples. Most likely it doesn't work with the format you are passing.

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

How to format Data object received from REST database ?

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 ?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to format Data object received from REST database ?

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());

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

How to format Data object received from REST database ?

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to format Data object received from REST database ?

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)

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

How to format Data object received from REST database ?

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. Image Image Image

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

How to format Data object received from REST database ?

Is the .toDateString() still working? I tried to use it to change the date that my Database returned from REST but I can't seem to get the code above to work. The day label is in a grid loop so I ran the code from the day Label "Add JS" section. Image Image Image

Return to “Issues”