Hi! before answer you question I would recomend you to give a little fix in your model and your function names. Try to follow the PEP8 style guide for Python, in the guide is recommended using only capitalized words for naming classes with composite names, and function names should be lowercase with words separated by underscore. Thereby, would be more appropriate naming your function and class this way: class MailItemCountDeliveriesPerDate() and def json_deliv(). Fell free to accept or ignore this tip. Now, back to the question, the DateTimeField() is a implementation of the python datetime.datetime for storage in the database, so after you get the Date from the database you can use the timestamp() method in the related Date field. This will deliver the date in seconds format, then you just multiply by 1000 to get your Date in milliseconds. Hope this helps. Sorry if it got a little confusing. De: HJ Hello everyone I want to convert my Date from string to milliseconds this is my models.py class class mail_item_count_deliveries_perDate(models.Model): countDeliveries = models.IntegerField(default=0) Date = models.DateTimeField() this is my views.py def jsonDeliv(request): dataset = mail_item_count_deliveries_perDate.objects.all().values_list('Date','countDeliveries') data = list(dataset) return JsonResponse(data, safe=False)
[["2020-05-21T00:00:00Z", 5], ["2019-05-21T00:00:00Z", 1], ["2020-04-06T00:00:00Z", 3], ["2020-02-10T00:00:00Z", 2], ["2020-01-23T00:00:00Z", 4],
-- -- |
- RES: convert Date to milliseconds Samuel Nogueira