Date and time format

Hi everyone, I’m having trouble setting the date and time format correctly.

This is the format it shows:


and I need to set it as:


So, to do this I set in this:



DATE_INPUT_FORMATS =  ['%d/%m/%Y']

USE_I18N = True

USE_L10N = True

USE_TZ = True

Using DATE_INPUT_FORMATS = [’%d/%m/%Y’] but it does not work.

You’re specifying an input format. Are you looking to define how dates are going to be rendered on a page? (See DATE_FORMAT)

1 Like

Thanks. I understand that I am specifying the input form that way. But in this case, it is the framework itself that sets the date input.

Because the models is:

class chat (models.Model):
    id = models.AutoField(primary_key=True)
    user= models.EmailField(blank=True)
    ticket = models.IntegerField(default=1000, blank=True)
    day = models.DateField(auto_now_add=True)
    time = models.TimeField(auto_now_add=True)

As you can see there is models.DateField(auto_now_add=True), so it Django which stablish the date.So what I am looking for is that when a new entry is created in the database the date that is set follows the format DD/MM/YYYY.

Actually, you shouldn’t care how the date is formatted within the database. That’s internal, and not directly visible to you. All you should concern yourself with is ensuring that any dates you pass to the database are formatted correctly, and that you specify how you want the dates represented when you display them.