What's wrong with my code using Datediff?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
putmann
Junior Coder
Posts: 24
Joined: Mon Aug 20, 2007 1:15 am
Location: Queens,NY

What's wrong with my code using Datediff?

Post by putmann » Thu Aug 06, 2009 1:20 pm

Daydiff should equal 1. I get this message after I run the script:
09/01/2009 08/31/2009 Difference Between Today and FMQfiledate= 0

Code: Select all

VBStart
VBEND
Let>Today=09/01/2009
Let>FMQfiledate=08/31/2009
VBEval>DateDiff("d",%Today%,%FMQfiledate%),Daydiff
if>Daydiff=1
messagemodal>Gooddates
Else
messagemodal>%Today% %FMQfiledate% Difference Between Today and FMQfiledate= %Daydiff%
Endif
[/code]

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 06, 2009 1:36 pm

Code: Select all

VBStart
VBEND
Let>Today=09/01/2009
Let>FMQfiledate=08/31/2009
VBEval>DateDiff("d",#%Today%#,#%FMQfiledate%#),Daydiff
if>Daydiff=1
messagemodal>Gooddates
Else
messagemodal>%Today% %FMQfiledate% Difference Between Today and FMQfiledate= %Daydiff%
Endif

putmann
Junior Coder
Posts: 24
Joined: Mon Aug 20, 2007 1:15 am
Location: Queens,NY

What's wrong with my code using Datediff?

Post by putmann » Thu Aug 06, 2009 2:14 pm

Thanks

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Aug 07, 2009 4:01 am

Hi JRL,
extract from the Help File entry for VBEval wrote:This command sometimes causes confusion. As it is evaluating a VBScript expression the syntax used in the first part of the command - the VBScript expression - should be valid VBScript syntax. To pass Macro Scheduler variables, embed them with the % symbol. If passing a Macro Scheduler variable as a string, remember that VBScript expects strings with quote marks around them. See examples below.

Let>text=Hello World

VBEval>PointlessStringExample("%text%"),sametext
JRL - per the above, I can see why one might need double quotes " around the %text% variable... but why did you use # in your example? Is that an alternative to " that also works or is # the only thing that would work? (sorry, can't try this at the moment)

Marcus - if this is required syntax then could you please add an example to the Help File VBEval> topic showing it used and an explanation as to when the #'s should be added.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Its vbscript syntax, not Macro Scheduler

Post by gdyvig » Fri Aug 07, 2009 4:44 am

Hi,

The answer is here:

http://msdn.microsoft.com/en-us/library ... S.85).aspx

(Can't get the above to make a link)

In case they move their URL that is the vbscript user guide for describing the syntax for date and time constants. While text strings require a set of double quotes "", the dates and times require a pair of pound signs ## to be interpreted as date/time constants.

I also googled vbscript datediff and found most code examples enclosed date and time with "", but found a few that used the ##.



Gale

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Aug 07, 2009 4:59 pm

Thanks Gale,

I just had a chance to try this and see that double quotes " also work as in the modified example below:

Code: Select all

VBStart
VBEND
Let>Today=09/01/2009
Let>FMQfiledate=08/31/2009
VBEval>DateDiff("d","%Today%","%FMQfiledate%"),Daydiff
if>Daydiff=1
messagemodal>Gooddates
Else
messagemodal>%Today% %FMQfiledate% Difference Between Today and FMQfiledate= %Daydiff%
Endif
Yes, I see now this is a syntax requirement specific to the VBScript DateDiff function... and not specific to the MS VBEval> command... however when we use the VBEval> command, we run into things like this... so an example in the Help File showing the syntax would be helpful.

It could mention or show that either "" or ## can be used. It might even reduce support time eaten up by new users working with VBScript date functions... nothing wrong with that.

Gale, the ( and ) characters in that URL are causing the problem with display in your forum post. If you substitute the URL Encoded equivalents, it will display and work OK:

( = %28
) = %29

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Thanks again for your reply... and take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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