check if a date falls in the last week using date.js - javascript

i use date.js for doing certain date calculations.
i am able to find if the date falls in this week, the following returns true
dateFld.between(Date.monday(), Date.friday())
but I want to check if date falls in the previous week.
i am using the following code without luck.
alert(dateFld.between(Date.last().week().monday(), Date.last().week().sunday()));
please help.

Sunday is the first day of the week.
Date.last().week().monday()
Mon Sep 07 2015 00:00:00 GMT+0100 (GMT Daylight Time) Correct
Date.last().week().sunday()
Sun Sep 06 2015 00:00:00 GMT+0100 (GMT Daylight Time) Incorrect
Date.last().sunday()
Sun Sep 13 2015 00:00:00 GMT+0100 (GMT Daylight Time) Correct

Related

GSheets GS Dates are one day off for 3/9/2020 - 4/5/2020 all other days are correct

GS code comes back one day off when getting date from 3/9/2020 - 4/5/2020
All dates between 3/9/2020 - 4/5/2020 comeback incorrect.
Google sheet add date column with date 3/9/2020
Add code to gs below
Comes back: Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
3/9/2020
Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
4/5/2020
Sat Apr 04 2020 23:00:00 GMT-0600 (CST)
var data = SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
SpreadsheetApp.getUi().alert(data[0][0]);
Here is the google sheet: link
The dates come back correctly if I format it using GMT.
var formattedDate = Utilities.formatDate(data[0][0], "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
UTC, GMT and Daylight Saving Time
Neither UTC nor GMT ever change for Daylight Saving Time (DST). However, some of the countries that use GMT switch to different time zones during their DST period.
For example, the United Kingdom is not on GMT all year, it uses British Summer Time (BST), which is one hour ahead of GMT, during the summer months.

toDate with .utc is using local timezone

https://momentjs.com/docs/#/parsing/utc/
moment.utc(ts).format(); // 2018-10-25T05:00:00+00:00
moment.utc(ts).toDate(); // Thu Oct 25 2018 07:00:00 GMT+0200 (Central European Summer Time)
How do I get the toDate format of the date but lose the local timezone (so that the second line displays 05:00:00 GMT+0000 (Central European Summer Time)). I thought using ".utc" fixed this?

Browser shows repeating datetime values after DST change

I am trying to display some datatime values in the a data table, here is the example code
<html>
<head>
<script type="text/javascript">
console.log(new Date(2017,2,26,0,0,0));
console.log(new Date(2017,2,26,1,0,0));
console.log(new Date(2017,2,26,2,0,0));
console.log(new Date(2017,2,26,3,0,0));
</script>
</head>
<body>
</body>
</html>
the browser shows repeating values for 2 AM.
Here is the log output
Sun Mar 26 2017 00:00:00 GMT+0000 (GMT Standard Time)
Sun Mar 26 2017 02:00:00 GMT+0100 (GMT Daylight Time)
Sun Mar 26 2017 02:00:00 GMT+0100 (GMT Daylight Time) **(Should it not be 3am)**
Sun Mar 26 2017 03:00:00 GMT+0100 (GMT Daylight Time) **(Should it not be 4am)**
I know I can use Date.UTC()
console.log(new Date(Date.UTC(2017,2,26,0,0,0)));
console.log(new Date(Date.UTC(2017,2,26,1,0,0)));
console.log(new Date(Date.UTC(2017,2,26,2,0,0)));
console.log(new Date(Date.UTC(2017,2,26,3,0,0)));
But that will display wrong date time values in other time zones.
Can someone suggest a solution to this problem? Or can someone explain what is happening here...?
This behavior depends on where time zone that is currently set on your computer is participating in daylight savings time Does Everyone Observe Daylight Saving Time?
If you switch you locale to Iceland time zone, for instance, (UTC+00:00) Monrovia, Rejkjavik and execute the code in console:
new Date(2017,2,26,0,0,0)
new Date(2017,2,26,1,0,0)
new Date(2017,2,26,2,0,0)
new Date(2017,2,26,3,0,0)
You will see the output where all hours are observed:
Sun Mar 26 2017 00:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 01:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 02:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 03:00:00 GMT+0000 (Greenwich Standard Time)
For countries that do participate in daylight savings one our will be missing depending on their timezone.
You could also check (UTC+10:00) Brisbane, Australia you see that all hours from midnight of 26th to midnight of 27th of March are displayed correctly.
If you can use libraries I highly recomend you to use MomentJS, it will make your life easier.
console.log(moment("2017-02-26 00:00:00").format());
console.log(moment("2017-02-26 01:00:00").format());
console.log(moment("2017-02-26 02:00:00").format());
console.log(moment("2017-02-26 03:00:00").format());

Strange date parsing issue

I'm loading some dates comming from my database into a HTML table in a string format. The string looks like 31-AUG-13 I'm parsing this string into a date object using the below code:
var paymentDate = $(this).find('td.paymentDate').text();
var test = $.datepicker.parseDate('d-M-y', paymentDate);
Everything is ok so far and I'm getting this date object: Date {Sat Aug 31 2013 00:00:00 GMT+0300 (FLE Standard Time)} But once the year is bigger than 2023. In my case 31-JAN-24 and so on it is turning to 1924 and not 2024, so I'm getting these date objects:
Date {Thu Jan 31 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Fri Feb 29 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Mon Mar 31 1924 00:00:00 GMT+0300 (FLE Standard Time)}
Date {Wed Apr 30 1924 00:00:00 GMT+0300 (FLE Standard Time)}
And so on. My question is regarding this strange issue. Is there a way to declare the year range and why it is going back to 1900 in the case when the year is bigger than 2023?
This teaches a lesson always use year in full format same was case with y2k problem. Convert date from database in to yyyy format then use it.

invalid date/time string: Sun Jun 03 2012 00:00:00 GMT+0100 (GMT Daylight Time) CFML

I'm trying to query to database using information from a html input. The format of the date is:
Date {Sun Jun 03 2012 00:00:00 GMT+0100 (GMT Daylight Time)}
In the database query I used
parseDateTime( arguments.start )
.. where arguments.start represents the date format shown above. But when I try to run the query, I get the response below from the web page:
invalid date/time string: Sun Jun 03 2012 00:00:00 GMT+0100 (GMT
Daylight Time)
Not sure what format you have there, but that is not a valid ISO 8601 time format. All ISO times formats are always GMT and are one of the following formats:
1994-11-05T13:15:30Z
1994-11-05T08:15:30-05:00
I would check whatever is giving you that string value.

Categories

Resources