How to check if current date/time is within a date/time range

This forum contains topics that were moved from Get Satisfaction
Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

How to check if current date/time is within a date/time range

Post by Takis »

Hi

I want to construct a dynamic where clause to check current date/time is within a date/time range (start, end).
Can I do the same with a +1 or -1 hour range?

Thanks.

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

How to check if current date/time is within a date/time range

Post by Takis »

This seems to work
I will check further

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
return '{"DateStart":{"$gte":"'+ dateStr +'"}}';

Example
{$and: [{ "ValidFrom": {$lte: "2014-11-11T00:00:00.000Z"} },{ "ValidTo": {$gte: "2014-11-11T00:00:00.000Z"} } ] }

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

How to check if current date/time is within a date/time range

Post by Takis »

When I use this code in button

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
alert (dateStr);

I get 2 hours time difference.
Do I need to setup time zone?
Is the date not taken from the system, mobile timezone?

Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to check if current date/time is within a date/time range

Post by Evgene Karachevtsev »

Hello Panagiotis,

The toISOString() method returns a string in ISO format (ISO 8601 Extended Format), which can be described as follows: YYYY-MM-DDTHH:mm:ss.sssZ. The timezone is always UTC as denoted by the suffix "Z".
read more here https://developer.mozilla.org/en-us/d...
You can add the offset of a timezone to the date to obtain the desired value
https://developer.mozilla.org/en-us/d...
prevar d = new Date();
d.setHours(d.getHours(), d.getMinutes() - d.getTimezoneOffset());
var dateStr = d.toISOString();
alert (dateStr);/pre

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

How to check if current date/time is within a date/time range

Post by Takis »

Thanks! it works Fine!

Post Reply