HOW TO GET RANDOM DATE BETWEEN TWO DATES

Discussion in 'Free Source Codes' started by sattam, Dec 22, 2022.

    
  1. sattam

    sattam Active Member


    Dear Expert Please suggest

    I tried $$RandomNumber but not get result
     


  2. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    All date has a numerical value .... e.g. 15-Dec has a value 44910 ..........
    So find the number (from Excel) of the FROM and TO Date........
    Then Use the Function ---- $$RandomNumber:44896:44926 ... Both are numerical values for 01-Dec and 31-Dec..........

    Then convert this back to DATE format.
     
    sattam likes this.


  3. sattam

    sattam Active Member


    Okay check this tomorrow. Thanks Amit ji.
     


  4. sattam

    sattam Active Member


    But How I tried $$Date:($$Number:44896)
    There Must be some function to convert number to date
     


  5. Chandresh J Geria

    Chandresh J Geria New Member


    type this function in a1
    =RANDBETWEEN(DATE(2022,12,1),DATE(2022,12,31))
    use above function in excel
    and type =TEXT(a1,"DD/MMM/YYYY")
    now you may double click on =RANDBETWEEN(DATE(2022,12,1),DATE(2022,12,31))
    this will change date within given range
     


  6. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    Try...this way ...... $$Date:"01-01-1901" which has a value of 1 ...... add the random number to this and deduct 1.
     


  7. sattam

    sattam Active Member


    I know this method of excel Mr. Chandresh.
    I want this in Tally
     


  8. sattam

    sattam Active Member


    Ok I will try.
     


  9. sattam

    sattam Active Member


    Thanks Amit ji it worked
    I used ($$Date:##AutoSaleEntryPostVar1)+ $$RandomNumber:1:30 where ##AutoSaleEntryPostVar1 store as Month start date
    But one more problem I want to get this date filtered
    that is $$DayOfWeek:$Date = "Monday" or $$DayOfWeek:$Date = "Tuesday"

    is it possible ?
     


  10. sattam

    sattam Active Member


    Another Way I tried

    [Collection:SaleDateColl]

    Type:Voucher
    Title:"List Of Dates"
    Fetch:Date
    Format:$Date,20
    Table Sort:$Date
    Filters:SaleDateflt1,SaleDateflt2

    [System:Formula]

    SaleDateflt1:($Date >= ##AutoSaleEntryPostVar1) And ($Date <= ##AutoSaleEntryPostVar4)
    SaleDateflt2: $$DayOfWeek:$Date = "Monday" or $$DayOfWeek:$Date = "Tuesday"

    from above collection I get the required date but how to use this collection dates in a fields randomly

    like for December month I get six date 5-12,6-12,12-12,13-12,19-12,20-12
    but how to use this date Randomly from collection
     


  11. Chandresh J Geria

    Chandresh J Geria New Member


    [#Menu:Gateway of Tally]
    ;;Title:$$Randomnumber:$$date:$$20221201:20221231
    Title:$$Randomnumber:20220501:20220531

    this will work well for one month
     


  12. narayane88

    narayane88 Active Member


    Sir another one method for random number get no of days in two date & use Randome function for 0 to differtioal day and get result add in to starating days following code get reuslt call function like $$GetRandomDate:$StartDate:$EndDate




    (code not tested)

    Code:
    [Function:GetRandomDate]
        Variable:StartP1:Date
        Variable:EndP2:Date
        Variable:DifferenceDays:Number
        Variable:result:Date
        Return:Date
       
        100:Set:DifferenceDays:$$Number:(##EndP2-##StartP1)
        110:Set:DifferenceDays:$$RandomNumber:1:##DifferenceDays
        120:Set:result:$$date:(##StartP1+##DifferenceDays)
        130:Return:result
        
     


  13. sattam

    sattam Active Member


    I tested your Function
    By some Minor Changes I get RandomDate
    Code:
    [Function:GetRandomDate]
      
        Parameter:StartP1        :Date
        Parameter:EndP2            :Date
        Variable:DifferenceDays    :Number
        Variable:result            :Date
      
        Return    :Date
      
      
        100:Set:DifferenceDays:$$Number:(##EndP2-##StartP1)
        110:Set:DifferenceDays:$$RandomNumber:0:##DifferenceDays
        120:Set:result:$$Date:(##StartP1+##DifferenceDays)
        ;122:Set:GetRandomDate:##result
        130:Return:##result
    But Problem is
    1)I want to use Random date in a repeated field (which will store different date value) under company object
    2) I want to get those random date which is "Monday" or "Tuesday"
     
    Last edited: Dec 28, 2022
    SINTO PARAVA likes this.


  14. narayane88

    narayane88 Active Member


    i dont undrestand 1 query
    2 use while loop for random result for getting $$weekofday:##result = "Monday" or "Tuesday"
     
    Last edited: Dec 27, 2022


  15. sattam

    sattam Active Member


    How to store this random Dates in a aggregate udf field
     


  16. narayane88

    narayane88 Active Member


    with help of function like

    Code:
    [Function:SetAggtValue]
        50:Walk Collection:YourColl
        100:Insert Collection Object:AggUdf Name
        110:Set Value:YourDateUdf:$$GetRandomDate:$StartDate:$EndDate
        120:Set Target:..
        130: End Walk
    
     


  17. murtyms

    murtyms New Member


    Hope this may give some idea
     

    Attached Files:

    sattam likes this.


  18. sattam

    sattam Active Member


    Wow Mr. Murtyms its awesome .I have little bit weakness in function.
    this is exactly what I want
    Thank you very much
    You really help me to get more knowledge about function
    Thanks again
     


  19. murtyms

    murtyms New Member


    Thank you .Sattamji I know your coding skills. In fact i am profited by your tdls. And I have great respect for you.
    However receiving an appreciation from an appreciated person gives immense happiness. Thank you once again.
     
    sattam likes this.


  20. SINTO PARAVA

    SINTO PARAVA Member


    yea.!! it looks good
     


Share This Page