Page 1 of 1

Pushing the Current Date & Time to database

Posted: Sun Jan 25, 2015 3:54 pm
by Lee Kraus

How do I push the current data and time into a date field in my database when I save a record? i.e. I what to save a started_at time in addition to the created_at time to indicate an event has started.

Thank you.


Pushing the Current Date & Time to database

Posted: Mon Jan 26, 2015 7:38 am
by Evgene Karachevtsev

Hello Lee,

Please look at this post:
https://getsatisfaction.com/apperyio/...


Pushing the Current Date & Time to database

Posted: Mon Jan 26, 2015 11:50 am
by Lee Kraus

It didn't work for me. Not sure if I am putting it in the wrong place? It is in the JS on the field in the request mapping component.


Pushing the Current Date & Time to database

Posted: Mon Jan 26, 2015 12:01 pm
by Lee Kraus

Nevermind, I got it to work. I need to change the timezone on my database. how do I do that?

Thank you!!!


Pushing the Current Date & Time to database

Posted: Tue Jan 27, 2015 1:48 pm
by Evgene Karachevtsev

Lee,

Unfortunately this cannot be done, all dates are written with UTC, if it is necessary, you can transfer them in the application


Pushing the Current Date & Time to database

Posted: Tue Jan 27, 2015 1:55 pm
by Lee Kraus

is there an easy formula to do that? I am not a programmer.

Thank you!


Pushing the Current Date & Time to database

Posted: Tue Jan 27, 2015 2:02 pm
by M&M

Well, assuming I understand you correctly, you just need this method

var UTCstring = (new Date()).toUTCString();

But do remember that the date values you get are based on the clock of the client's machine, not your server


Pushing the Current Date & Time to database

Posted: Tue Jan 27, 2015 2:05 pm
by M&M

And how would you use that?

You can add a new col / field in your table called _insertedAt or something...and then in your mapping when you call the REST API / or within your Before Send - add the following in the "JS" for that column

var UTCstring = (new Date()).toUTCString();
return (UTCstring);

This will supply the client side time (in UTC, of course) to the REST Call and that way you can have the record insertion time


Pushing the Current Date & Time to database

Posted: Tue Jan 27, 2015 2:12 pm
by Lee Kraus

Thank you. I will test. I appreciate the support.