Quantcast

Extract Date-From and Date-To in DateRangeField django

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Extract Date-From and Date-To in DateRangeField django

RON MICHAEL
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 [hidden email].
To post to this group, send email to [hidden email].
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/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extract Date-From and Date-To in DateRangeField django

roboslone
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com.
For more options, visit 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 [hidden email].
To post to this group, send email to [hidden email].
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extract Date-From and Date-To in DateRangeField django

RON MICHAEL
No NOT duration. I simply want to get the date_from and the date_to which is inside the DateRange. 

On Friday, February 17, 2017 at 8:13:39 PM UTC+8, Александр Христюхин wrote:
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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OQzLG2NDBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ronmicha...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OQzLG2NDBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OQzLG2NDBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/848d9e95-4701-4984-bfee-64526621084e%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To post to this group, send email to [hidden email].
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/3ff094ad-8153-4e8e-9440-80a2b0057667%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extract Date-From and Date-To in DateRangeField django

Melvyn Sopacua

On Friday 17 February 2017 06:24:25 RON MICHAEL wrote:

> No NOT duration. I simply want to get the date_from and the date_to

> which is inside the DateRange.

 

You mean the lower and upper.

 

--

Melvyn Sopacua

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/1649242.ZoGe6X4TC5%40devstation.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extract Date-From and Date-To in DateRangeField django

RON MICHAEL
Yes that's it! Sorry, I lost the words there :D

On Friday, February 17, 2017 at 10:40:14 PM UTC+8, Melvyn Sopacua wrote:

On Friday 17 February 2017 06:24:25 RON MICHAEL wrote:

> No NOT duration. I simply want to get the date_from and the date_to

> which is inside the DateRange.

 

You mean the <a href="http://initd.org/psycopg/docs/extras.html#psycopg2.extras.DateRange" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Finitd.org%2Fpsycopg%2Fdocs%2Fextras.html%23psycopg2.extras.DateRange\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGSvB7WodK13Lrm02Pukr-2VTPsjw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Finitd.org%2Fpsycopg%2Fdocs%2Fextras.html%23psycopg2.extras.DateRange\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGSvB7WodK13Lrm02Pukr-2VTPsjw&#39;;return true;">lower and upper.

 

--

Melvyn Sopacua

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/f344d0d9-561a-452b-9b83-525bbd4606f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...