Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Unhappy ColdFusion Date Logic Assistance Needed

    I am embarrassed to admit that I am not the greatest when it comes to dates and date logic ColdFusion.

    I<!---checks frequency for form schedule and sets datepart. RecordType_Frequency is a column in database daily, weekly, monthly etc.--->

    <CFSWITCH expression="#RecordType_Frequency#">

    <CFCASE value="Daily">

    <CFSET datepart = "d">


    <CFCASE value="Weekly">

    <CFSET datepart = "ww">


    <CFCASE value="Monthly">

    <CFSET datepart = "m">


    <CFCASE value="Quarterly">

    <CFSET datepart = "q">


    <CFCASE value="Yearly">

    <CFSET datepart = "yyyy">



    <!---setting dates based on database values for when the form should schedule--->

    <!---enddate Uses the RecordType_Frequency_StartDate column from the database which is a date in the past. Coefficient is a stored db value for the frequency 1,2 etc. for could scheduled every 1 year, 2 year --->

    <cfset enddate = datediff(datepart,RecordType_Frequency_StartDate,todaydate) + Coefficient>

    <!---start date is set to current RecordType_Frequency_StartDate which is a column value from the database--->

    <cfset startdate = RecordType_Frequency_StartDate>

    <!---sets the next start date for when the for should schedule based on historic db start date--->

    <cfset new_date = #dateformat(DateADD(datepart,Coefficient,startdate),'MM-DD-YYYY')#>

    <cfloop from="1" to="#enddate#" index="i">

    <cfset new_date = #dateformat(DateADD(datepart,Coefficient,startdate),'MM-DD-YYYY')#>

    <cfset startdate = new_date>

    <cfset diff = datediff(datepart,RecordType_Frequency_StartDate,startdate)>

    <cfif (startdate GT #todaydate#)>

    <cfset next_date= startdate>


    <!---I need this output to equal the next date value that would fall based on the schedule, future date. I am seeing multiple dates and need to figure out how to capture would weould truly be the next scheduled date--->

    Next Date = #diff# - #dateformat(next_date)#<br />




    In summary, I have forms that are on a schedule. The start/set up date is the only date that I have to use. I need to to grab or populate the next scheduled date for the form using what information I have. Obviously the next creation date needs to fall in the future as this date will be used in conjunction with a scheduled event.

    I have posted the code with comments and need help grabbing the next logical date closest to the current date that should fall in sequence.

    Any help would be very much appreciated.


  2. #2
    Regular Coder
    Join Date
    Apr 2012
    St. Louis, MO
    Thanked 101 Times in 101 Posts
    You are not using a mask in your DateFormat. Is next_date actually returning as a valid date?

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts