Questions tagged [datefield]
307 questions
35
votes
5 answers
How can my django model DateField add 30 days to the provided value?
as the title suggests. I want to add 30 days to the DateField field. This is auto populated on creation of record using auto_now_add=True
Any ideas how to go about doing this?
Thanks

dotty
- 40,405
- 66
- 150
- 195
31
votes
4 answers
Only showing year in django admin, a YearField instead of DateField?
I've got a model where I need to store birth year. I'm using django admin. The person using this will be filling out loads of people every day, and DateField() shows too much (not interested in the day/month).
This is a mockup model showing how it…

odinho - Velmont
- 20,922
- 6
- 41
- 33
30
votes
5 answers
How can I set a DateField format in django from the model?
I am creating a django application and I have the next problem: this error is shown when I want to set a date:
ValidationError [u"'12/06/2012' value has an invalid date format. It must be in YYYY-MM-DD format."]
For this model:
class…

jartymcfly
- 1,945
- 9
- 30
- 51
23
votes
4 answers
Django: How to set DateField to only accept Today & Future dates
I have been looking for ways to set my Django form to only accept dates that are today or days in the future. I currently have a jQuery datepicker on the frontend, but here is the form field to a modelform.
Thanks for the help, much…

Emile
- 3,464
- 8
- 46
- 77
20
votes
4 answers
Django: How to format a DateField's date representation?
I have a form with a DateField. The existing date value is formatted to render like this:
2009-10-03
How can I format that so that it look like this:
03.10.2009
I found a widget which renders it like this, but validation doesn't allow the values I…
falstaff
13
votes
3 answers
Using datetime to compare with dates in Django
I have a question in Django on how you can compare dates to solve some solutions. For example I have a datefield in my models.py Like below.
class Invoice(models.Model):
payment_date = models.DateTimeField()
What I want to be able to do is ask…

Shehzad009
- 1,547
- 6
- 28
- 42
11
votes
2 answers
Django DateField with only month and year
I post this because I could not find an answer/example that satisfied me and I solved it a way I haven't read in there. Maybe it can be useful or can be discussed.
Basically, my app displays formsets where users can create objects. Once validated,…

stockersky
- 1,531
- 2
- 20
- 36
11
votes
3 answers
Django DateField without year
Is it possible to have a DateField without the year? Or will I have to use a CharField? I am using the admin to edit the models.

Ali
- 4,311
- 11
- 44
- 49
10
votes
1 answer
ExtJS 5 xtype datefield is not working when selecting month or year
When clicking on the dropdown to select individual months/years the dialog disappears like I am trying to click away.
fiddle: https://fiddle.sencha.com/#fiddle/9m6
Ext.onReady(function() {
Ext.create('Ext.form.Panel', {
title:…
user4067565
10
votes
2 answers
How to set the default value of datafield - EXTJS 4
var startdt = Ext.create('Ext.form.DateField',{
fieldLabel: 'Start Date',
name: 'startdt',
id: 'startdt',
vtype: 'daterange',
format: 'd/m/Y',
endDateField: 'enddt', // id of the end date field
value = new date()
…
user1972227
9
votes
2 answers
Django date validation, help needed
I tried to validate my DateField to accept only dates from today and future, but I don't know why it's accepting every passed date anyway.
My models.py file:
def present_or_future_date(value):
if value < datetime.date.today():
raise…

Kaspazza
- 303
- 1
- 3
- 13
9
votes
2 answers
Django python: Using DateInput --Required argument 'year' (pos 1) not found
I'm trying to use DateInput, but I get the following error
Required argument 'year' (pos 1) not found here {{ form.incident_date_time_reported|add_class:"form-control"}} (line 52)
forms.py
from django import forms
import datetime
from functools…

user1807271
- 946
- 3
- 13
- 32
8
votes
3 answers
How to select a date in a Rails date_field form helper using Capybara
I have a reservation search form that contains the following date_field helper:
<%= date_field(:reservation, :arrival_date) %>
How do I select a specific date for this date_field tag using Capybara?
I tried select "2014-01-01", from:…

Adler Santos
- 365
- 5
- 19
7
votes
2 answers
Change Date format in Django model
I have a date field called "birthdate" and property called "lifespan" in a django model.
Field
birthdate = models.DateField(blank=True, null=True)
Property
@property
def lifespan(self):
return '%s - present' % self.birthdate
Currently lifespan…

bbrooke
- 2,267
- 10
- 33
- 41
7
votes
4 answers
Making Django forms.DateField show use local date format
I'm trying to find an easy way to build forms which show dates in the Australian format (dd/mm/yyyy). This was the only way I could find to do it. It seems like there should be a better solution.
Things to note:
Created a new widget which…

olivergeorge
- 355
- 2
- 4
- 8