First of all, I am new to javascript and hence if my question doesn't make any sense, please pardon me.
I want to know what exactly this date represents : 2022-02-28T00:00:00.000Z
Here, it is understood that year is 2022, month is Feb and date is 28th. After that, it showing hour as 00, minutes as 00, seconds as 00 and milliseconds as 000. So, will it be 12 midnight of 28th, 12 midnight of 27th of Feb or something else?
I am asking this question because I have to filter some date based on date range. Suppose, I want the data from 11 to 20th of Feb 2022, then should I take toDate as 2022-02-20T00:00:00.000Z or 2022-02-20T23:59.59.999Z ??
CodePudding user response:
So, will it be 12 midnight of 28th, 12 midnight of 27th of Feb or something else?
2022-02-28T00:00:00.000Z
will be considered as the 28th midnight.
Let's look at this with an example:
//Date: 30th
var endDate = Date.parse("2022-07-30T00:00:00.000Z");
//Date: 29th
var currentDate = Date.parse("2022-07-29T11:59:59.999Z");
//Return true
console.log(endDate > currentDate);
The endDate is considered greater than the currentDate.
//Date 30th
var endDate = Date.parse("2022-07-30T00:00:00.000Z");
//Date: 30th, Time:1/1000th of a second
var currentDate = Date.parse("2022-07-30T00:00:00.001Z");
//Return false
console.log(endDate > currentDate);
When current DateTime is .001Z greater than endDate. CurrentDate is considered greater than end date. Hence false.
Coming to your question,
Suppose, I want the data from 11 to 20th of Feb 2022, then should I take toDate as 2022-02-20T00:00:00.000Z or 2022-02-20T23:59.59.999Z ??
If you want to also consider the data that was created between
2022-02-20T00:00:00.000Z
and 2022-02-20T23:59.59.999Z
. That is, on the day of 20th Feb 2022. You need have condition as date <= 2022-02-20T23:59.59.999Z
or date < 2022-02-21T00:00.00.000Z
Or
If you want to consider the data that was created till 2022-02-19T23:59.59.999Z
. That is, till the end of the day of 19th Feb 2022. You can have condition as date <= 2022-02-19T23:59.59.999Z
or date < 2022-02-20T00:00:00.000Z
CodePudding user response:
the last zeros means that your datatype is for date column is current time stamp it will inserted automatically date with hour mins and secs.
if you want to fetch just date then the query will be like follow:
SELECT * date(column_name
) AS shor_date
FROM table_name;
CodePudding user response:
There is a useful library for date formats you can benefit from to transform this format to easier to filter as required in an easy way and much more functions provided. It is called momentjs
https://momentjs.com/