Tuesday, 4 April 2017

Start & End of day in local timezone

I am trying to assign a date range - start/end dates for a process. The catch is that the start date should be the 00:00:00 of the start date and end date should be 23:59:59 of the end date in the timezone that my server is in.

Input is 4/4/2017

Following is my code snippet,

var pEnddate = formatDate (campaign.CMPGN_DTL_TX.CMPGN_END_DT, "yyyy-mm-dd 23:59:59");
                            pEnddate.then (function ( endDate ) {
                                var endDate1 = moment.tz (endDate, "America/Phoenix").format ();
                                campaign.CMPGN_DTL_TX.CMPGN_END_DT = endDate1;}

It is going good for the first time and saving in UTC as "CMPGN_END_DT" : ISODate("2017-04-05T06:59:59.000+0000")

When I try editing it, the next time the date from my TS is coming as "CMPGN_END_DT" : ISODate("2017-04-05T06:59:59.000+0000"). But, the date is changing to the next date, which is CMPGN_END_DT" : ISODate("2017-04-05T23:59:59.000+0000") because I am hard-coding the time. I'm doing this to ensure I set it to the end of day. Because of this, every time I execute this code (which is when I'm updating the related process), the date is getting incremented by 1.

The only workaround I could figure out was to set it to the EOD without having to hard-code it. Is there some way I can achieve this?



via Ramana Sarva

No comments:

Post a Comment