Skip to main content
johng58900177
Known Participant
June 18, 2020
Question

places

  • June 18, 2020
  • 2 replies
  • 323 views

if I want to us a certain number of places in an order number how would I do so? it is comprised of the date and 4 more places which is the cordcount of the date entered plus 1.

 

I have this working but not with the extra 0's in front of the second part of the order number. So today would start with 061720202 which is the second order of the day. I want 06172020002

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    June 22, 2020
    <cffunction name="getOrderNumber" returntype="string" hint="Generates the order number for given date and N-th order of the day">
    	<cfargument name="N" required="true" hint="The N-th order of the day">
    	<cfargument name="theDate" default="#now()#" hint="Date (as String)">
    		
    	<cfset var n_th_order_of_the_day=arguments.N>
    	
    	<cfset var dateString=arguments.thedate>
    	<!--- The date object. Alternatively, use createdate() to define it.  --->
    	<cfset var dateObject=parseDatetime(dateString)>
    	
    	<cfset var orderNumber=dateFormat(dateObject,"mmddyyyy") & right("0000" & n_th_order_of_the_day,4)>
    	
    	<cfreturn orderNumber>
    </cffunction>
    
    <cfoutput>
    Order number 2 of 6/17/2020, getOrderNumber(2,"6/17/2020"): <br>
    #getOrderNumber(2,"6/17/2020")# <br><br>
    
    Order number 12 of today (the default date), getOrderNumber(12): <br>
    #getOrderNumber(12)#
    </cfoutput>
    WolfShade
    Legend
    June 18, 2020

    So, how is this number generated?

     

    <cfset ordNum = DateFormat(now(),'mmddyyyy') & NumberFormat(x,'0000') />

     

     

    x is the order number of that day.

     

    V/r,

     

    ^ _ ^

    johng58900177
    Known Participant
    June 19, 2020

    I take a recordcount of all of the orders from that day and add 1 to it.

    WolfShade
    Legend
    June 22, 2020

    Then what I offered should be sufficient.  Calculate that number and place it where the 'x' is in the cfset, and you're all set.

     

    V/r,

     

    ^ _ ^