Hi, do you mean to store some kind of duration? There's DurationField for that. 
And you could store datetime.timedelta there. To get timedelta between two 
datetime.datetime objects, you could subtract ine from another:


from django.utils import timezone as tz

now = tz.now()
day_ago = tz.now() - tz.timedelta(days=1)
duration = now - day_ago  # duration can be stored in DurationField

> On 17 Feb 2017, at 04:31, RON MICHAEL <ronmichaelbay...@gmail.com> wrote:
> 
> Hi! In my database I have a DateRangeField. What I want to do is get the 
> date-from and the date-to and store them in a separate variable like example:
> 
> date_from =DateRangeField(date_from)
> date_to =DateRangeField(date_to)
> 
> 
> of course that code won't work. My data is like this:
> 
> 'date_range': DateRange(datetime.date(2017, 2, 17), datetime.date(2017, 2, 
> 18), '[)')
> 
> 
> 
> How do I get those dates?
> 
> Btw, I've tried indexing this, and it doesn't work. I've tried iterating it, 
> but it also doesn't work. 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/14695B35-164D-480B-824F-DCBA8B9369AF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to