[Answered ]-In django i want to change the date from views

1👍

You can increment datetime on the basis of given days using timedelta

    from datetime import datetime  
    from datetime import timedelta #new

    today = datetime.now() 
    print(f"Today's the date & Time is {today}")
    month_later = today+ timedelta(days=MONTHLY_CYCLE)
    three_months_later = today+ timedelta(days=QUA_CYCLE)
    six_months_later = today+ timedelta(days=SIX_MONTH_CYCLE)
    print(f"three_months_later's the date & Time is {month_later}")
    print(f"three_months_later's the date & Time is {three_months_later}")
    print(f"six_months_later's the date & Time is {six_months_later}")
    
    customer = Customer.objects.get(pk=id) # Targeted Customer 
    selected_cycle = int(customer.billing_cycle) #return the value of billing_cycle selected from Customer
    tentative_date = today+ timedelta(days=selected_cycle) 
    print(f"tentative_date Billing date & Time is {month_later}") # Required DAte.  

This is how you can update the datetime. rest you can implement as required.

Leave a comment