Velocity date incorrect month | Community
Skip to main content
Joe_Luthy
New Participant
October 25, 2022
Solved

Velocity date incorrect month

  • October 25, 2022
  • 1 reply
  • 1511 views

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
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
October 25, 2022

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
Joe_LuthyAuthor
New Participant
October 25, 2022

Thank you very much.