Skip to main content
johng58900177
Known Participant
Jun 18, 2020 12:22 AM UTC
Question

places

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 is closed to new replies. Start a new post to keep the conversation going.

    4 replies

    BKBK
    Community Expert
    Community Expert
    Jun 22, 2020 1:01 PM UTC
    <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>
    Translate
    WolfShade
    Legend
    Jun 18, 2020 1:34 PM UTC

    So, how is this number generated?

     

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

     

     

    x is the order number of that day.

     

    V/r,

     

    ^ _ ^

    Translate
    johng58900177
    Known Participant
    Jun 19, 2020 10:49 PM UTC

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

    Translate
    WolfShade
    Legend
    Jun 22, 2020 2:41 PM UTC

    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,

     

    ^ _ ^

    Translate