iso8601

Format date in MySQL SELECT as ISO 8601

别等时光非礼了梦想. 提交于 2019-11-27 21:00:24
I'm trying to grab the date from my database in a standard timestamp and display it as ISO 8601. I'm unable to easily do it in PHP so I'm trying to do it in my SELECT statement. This is what I have, but it displays an error: SELECT * FROM table_name ORDER BY id DESC DATE_FORMAT(date,"%Y-%m-%dT%TZ") What am I doing wrong? The DATE_FORMAT(DateColumn) has to be in the SELECT list: SELECT DATE_FORMAT(date, '%Y-%m-%dT%TZ') AS date_formatted FROM table_name ORDER BY id DESC DATE_FORMAT only works on MySQL date columns, not timestamps. A UNIX timestamp is an integer containing the number of seconds

MySQL insert to DATETIME: is it safe to use ISO::8601 format?

孤街醉人 提交于 2019-11-27 20:39:33
In our project we use Zend Framework Model generator, which produces something like this to set the properties that are stored in DB (MySQL) as DATETIME fields: public function setObjectDatetime($data) { if (! $data instanceof Zend_Date) { ... some conversion code ... } $this->objectDatetime = $data->toString(Zend_Date::ISO_8601); } So the ISO::8601 formatted string ('2012-06-15T18:33:00+03:00' for example) is what actually is stored as a property. The problem arises when we try to save this model, and pass this string to MySQL (version 5.5.16): it raise the warning, but still inserts/updates

Converting timezone-aware datetime to local time in Python

情到浓时终转凉″ 提交于 2019-11-27 17:31:23
How do you convert a timezone-aware datetime object to the equivalent non-timezone-aware datetime for the local timezone? My particular application uses Django (although, this is in reality a generic Python question): import iso8601 .... date_str="2010-10-30T17:21:12Z" .... d = iso8601.parse_date(date_str) foo = app.models.FooModel(the_date=d) foo.save() This causes Django to throw an error: raise ValueError("MySQL backend does not support timezone-aware datetimes.") What I need is: d = iso8601.parse_date(date_str) local_d = SOME_FUNCTION(d) foo = app.models.FooModel(the_date=local_d) What

ISO time (ISO 8601) in Python

前提是你 提交于 2019-11-27 16:44:54
I have a file. In Python, I would like to take its creation time, and convert it to an ISO time (ISO 8601) string while preserving the fact that it was created in the Eastern Time Zone (ET) . How do I take the file's ctime and convert it to an ISO time string that indicates the Eastern Time Zone (and takes into account daylight savings time, if necessary)? estani Local to ISO 8601: import datetime datetime.datetime.now().isoformat() UTC to ISO 8601: import datetime datetime.datetime.utcnow().isoformat() Local to ISO 8601 without microsecond: import datetime datetime.datetime.now().replace

Can strict JSON $dates be used in a MongoDB query?

微笑、不失礼 提交于 2019-11-27 15:56:47
问题 I'm trying to write a date comparison query using MongoDB's strict JSON representation of BSON . I'd like it to work in the MongoDB shell (v2.4.3) Here's what I've tried... Setup: create a new document with an at date of Jan 1, 2020 > db.myTimes.insert({"at": new Date("2020-01-01")}) Using non-strict query for date > 2010, no problem: > db.myTimes.find({"at": {"$gt": new Date("2010-01-01")}}) { "_id" : ObjectId([snipped]), "at" : ISODate("2020-01-01T00:00:00Z") } Using strict JSON query,

Sort array by ISO 8601 date

被刻印的时光 ゝ 提交于 2019-11-27 14:43:45
问题 how can i sort this array by date (ISO 8601)? var myArray = new Array(); myArray[0] = { name:'oldest', date:'2007-01-17T08:00:00Z' } myArray[1] = { name:'newest', date:'2011-01-28T08:00:00Z' } myArray[2] = { name:'old', date:'2009-11-25T08:00:00Z' } Playground: http://jsfiddle.net/4tUZt/ Thanks in advance! 回答1: Sort Lexicographically: As @kdbanman points out, ISO8601 See General principles was designed for lexicographical sort. As such the ISO8601 string representation can be sorted like any

PHP validate ISO 8601 date string

大憨熊 提交于 2019-11-27 14:37:42
问题 How do you validate ISO 8601 date string (ex: 2011-10-02T23:25:42Z). I know that there are several possible representations of ISO 8601 dates, but I'm only interested in validating the format I gave as an example above. Thanks! 回答1: This worked for me, it uses a regular expression to make sure the date is in the format you want, and then tries to parse the date and recreate it to make sure the output matches the input: <?php $date = '2011-10-02T23:25:42Z'; var_dump(validateDate($date)); $date

Python - Convert string representation of date to ISO 8601

不想你离开。 提交于 2019-11-27 13:51:30
In Python, how can I convert a string like this: Thu, 16 Dec 2010 12:14:05 +0000 to ISO 8601 format, while keeping the timezone? Please note that the orginal date is string, and the output should be string too, not datetime or something like that. I have no problem to use third parties libraries, though. unutbu Using dateutil : import dateutil.parser as parser text = 'Thu, 16 Dec 2010 12:14:05 +0000' date = parser.parse(text) print(date.isoformat()) # 2010-12-16T12:14:05+00:00 Python inbuilt datetime package has build in method to convert a datetime object to isoformat. Here is a example: >>

How to format an UTC date to use the Z (Zulu) zone designator in php?

故事扮演 提交于 2019-11-27 12:20:22
I need to display and handle UTC dates in the following format: 2013-06-28T22:15:00Z As this format is part of the ISO8601 standard I have no trouble creating DateTime objects from strings like the one above. However I can't find a clean way (meaning no string manipulations like substr and replace, etc.) to present my DateTime object in the desired format. I tried to tweak the server and php datetime settings, with little success. I always get: $date->format(DateTime::ISO8601); // gives 2013-06-28T22:15:00+00:00 Is there any date format or configuration setting that will give me the desired

How do I format a date as ISO 8601 in moment.js?

心已入冬 提交于 2019-11-27 09:30:31
问题 This docs mention moment.ISO_8601 as a formatting option (from 2.7.0 - http://momentjs.com/docs/#/parsing/special-formats/), but neither of these work (even 2.7.0): var date = moment(); date.format(moment.ISO_8601); // error moment.format(date, moment.ISO_8601); // error (http://jsfiddle.net/b3d6uy05/1/) How can I get an ISO 8601 from moment.js? 回答1: moment().toISOString(); // or format() - see below http://momentjs.com/docs/#/displaying/as-iso-string/ Update Based on the answer: by @sennet