Is between dates

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
bjorn82dk
Newbie
Posts: 13
Joined: Sat Jun 23, 2012 10:41 am
Location: Copgenhagen, Denmark

Is between dates

Post by bjorn82dk » Tue Mar 17, 2015 7:00 am

Hello all scripters,
I have started to wok with dates in my scripting and for the time being I have to issues I can't seem to crack, hope some of you can help me out.

1. Problem. Get global date and time.
I would like to get the date and time information from www - and I would suspect that there would be some kind of service that can help me, any ideas? My though was to use a httpget command and in return get current date and time (GMT is okay). There might be another solution to this so feel free to post any ideas.

2. Is date/time between.
I need to check if current date and time is within/between to other date values. I have spend hours on MS but still haven't found the right solution. Can anybody give me a hand with this?

Exampel:
Let>Time1=01-01-2015 12:00:00
Let>Time2=01-12-2015 12:00:00
Let>TimeNow=TimeNow
if.... something to check if timenow is between Time1 and Time2.

Best regards and thanks in advance.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Is between dates

Post by Marcus Tettmar » Tue Mar 17, 2015 11:00 am

Hi,

1. By default Windows syncs with an SNTP time server. So your computer should already be able to tell you the correct time and you shouldn't therefore need to request a date/time from the internet.

However, if you want to you can and there are several services out there. Here's one with an example:

Code: Select all

// http://www.earthtools.org/webservices.htm
Let>url=http://www.earthtools.org/timezone/40.71417/-74.00639
HTTPRequest>url,,GET,,xmlres
XMLParse>xmlres,/timezone/utctime/text(),date_time,n
This actually requests the time for New York (using New York's Lat and Long) but whatever you request it also returns utc time which I am pulling out in my example.

2. VBScript's DateDiff function gives you a nice way to determine time between dates. This looks to see if two date times are between the current date/time:

Code: Select all

Let>Time1=01-01-2015 12:00:00
Let>Time2=01-12-2015 12:00:00

VBEVal>DateDiff("s",now(),"%Time1%"),diff1
VBEVal>DateDiff("s",now(),"%Time2%"),diff2

If>{(%diff1%<0) AND (%diff2%>0)}
  MessageModal>today is between the dates
Endif
This uses VB's now() function, so it's using local system time, which should be synced via SNTP anyway. But if you wanted to combine the above two examples so that you're comparing with the utc time retrieved from the web service, here's the full example:

Code: Select all

// http://www.earthtools.org/webservices.htm
Let>url=http://www.earthtools.org/timezone/40.71417/-74.00639
HTTPRequest>url,,GET,,xmlres
XMLParse>xmlres,/timezone/utctime/text(),date_time,n

Let>Time1=01-01-2015 12:00:00
Let>Time2=01-12-2015 12:00:00

VBEVal>DateDiff("s","%date_time%","%Time1%"),diff1
VBEVal>DateDiff("s","%date_time%","%Time2%"),diff2

If>{(%diff1%<0) AND (%diff2%>0)}
  MessageModal>today is between the dates
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

bjorn82dk
Newbie
Posts: 13
Joined: Sat Jun 23, 2012 10:41 am
Location: Copgenhagen, Denmark

Re: Is between dates

Post by bjorn82dk » Tue Mar 17, 2015 7:43 pm

Hello Marcus,
You amaze me once again (ment in the most positive way I can express it). I have been searching the www for last many many hours and as a free of charge service you quickly reply to my post with an answer.

I will try it out in the morning and see if I can get it to work.

I have said this before - but I will say it once more, buying the MS Pro is one of the best value for money purchases I have ever done.

bjorn82dk
Newbie
Posts: 13
Joined: Sat Jun 23, 2012 10:41 am
Location: Copgenhagen, Denmark

Re: Is between dates

Post by bjorn82dk » Thu Mar 19, 2015 12:26 pm

Hi Macus,
Just to close this subject. I tried your solution and its working like a dream. Thank you so much.


Best regards and a nice weekend when you get there.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts