SOLVED

Velocity date incorrect month

Go to solution
Joe_Luthy
Level 1

Velocity date incorrect month

Hi, 

I am attempting to use the Velocity date scripting to show specific event times based on the month.  Currently the actual month is October (10). But I was not getting the right output.  I modified the script to show the current date.  What displays is 2022/9/25 and the actual (current date) is 2022/10/25.  Can someone identify the issue

 

##Inserts next available class start
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Phoenix") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

#if( $calNow.get($calConst.MONTH) != 10 )
$calNow.get($calConst.YEAR)
$calNow.get($calConst.MONTH)
$calNow.get($calConst.DAY_OF_MONTH)
$calNow.get($calConst.DAY_OF_WEEK)

#end
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity date incorrect month

Remember to use the Syntax Highlighter when posting code. (I edited your post this time.)

 

There’s not actually an issue here. Gregorian months are zero-based, so January is 0.

 

P.S. When checking inequality, you should use not-equals:

#if( !$field.equals(value) )
## etc.

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity date incorrect month

Remember to use the Syntax Highlighter when posting code. (I edited your post this time.)

 

There’s not actually an issue here. Gregorian months are zero-based, so January is 0.

 

P.S. When checking inequality, you should use not-equals:

#if( !$field.equals(value) )
## etc.
Joe_Luthy
Level 1

Re: Velocity date incorrect month

Thank you very much.