So i need to remove from date Time, so i only get date, year and month.
"2014-04-17T00:00:00"
I looked at different opportunities but it didn't work
class Inventory(models.Model):
manufacturer = models.CharField(max_length=255)
model = models.CharField(max_length=255)
description = models.TextField(max_length=255)
count = models.IntegerField(max_length= 255, default=1)
location = models.ForeignKey('Location', null=True, blank=True)
cover = models.FileField(upload_to = 'static/images/', default = 'static/images/no-image.png')
created = models.DateTimeField(auto_now_add=True)
barcode = models.CharField(max_length=255)
assigned = models.ForeignKey(User, blank=True, null=True)
checked = models.BooleanField(default=False)
modified = models.DateTimeField(default=datetime.datetime.now)
tags = TaggableManager(through=None, blank=True)
def __unicode__(self):
return '%s' % date(self.modified, "n/j/Y")
def format_date(obj):
return obj.modified.strftime('%d %b %Y %H:%M')
format_date.short_description = 'Modified'
this works for me.
def get_date(self):
return self.modified.date()
You can parse the strftime with dateutil.parser :
import dateutil.parser
datetime_date = dateutil.parser.parse(strf_date)
And then get a strftime date with the part of the datetime you need. In your case, Year, Month, Day :
date_only = datetime_date.strftime("%Y-%M-%d")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With