Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to check if a date is expired or not django?

I have a model that contains informations about trips and one field is a DateTimeField() like this:

class Voyage(models.Model):
    voyid = models.CharField(max_length=20, primary_key= True)
    depart = models.CharField(max_length=30)
    destination = models.CharField(max_length=30)
    datedep = models.DateTimeField() #the datedep is the time and date of the trip departure 

And the result is a list of trips so i want to output only the trips that are not expired:
(datedep > now), how do i do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can .filter(…) [Django-doc] with Now [Django-doc] for the database timestamp:

from django.db.models.functions import Now

Voyage.objects.filter(datedep__gt=Now())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading