Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用peewee从SQL数据库读取特定格式的日期字段_Python_Peewee_Datefield - Fatal编程技术网

Python 使用peewee从SQL数据库读取特定格式的日期字段

Python 使用peewee从SQL数据库读取特定格式的日期字段,python,peewee,datefield,Python,Peewee,Datefield,我想从SQL数据库中读取一列日期。但是,数据库中日期的格式类似于2013年1月27日,即年月日。当我使用peewee DateField读取此列时,它的读取格式无法在以后使用datetime.date进行比较 有人能帮我解决这个问题吗?您需要使用%Y-%m-%d格式将数据存储在数据库中。当您提取数据时,您可以用您喜欢的任何格式来表示它,但为了确保数据被正确排序并被SQLite识别为日期,您必须使用%Y-%m-%d格式或unix时间戳(如果您愿意)。我没有使用peewee。但是你不把字符串转换成日

我想从SQL数据库中读取一列日期。但是,数据库中日期的格式类似于2013年1月27日,即年月日。当我使用peewee DateField读取此列时,它的读取格式无法在以后使用datetime.date进行比较


有人能帮我解决这个问题吗?

您需要使用%Y-%m-%d格式将数据存储在数据库中。当您提取数据时,您可以用您喜欢的任何格式来表示它,但为了确保数据被正确排序并被SQLite识别为日期,您必须使用%Y-%m-%d格式或unix时间戳(如果您愿意)。

我没有使用peewee。但是你不把字符串转换成日期时间格式吗?@Thothadri谢谢。当我不使用peewee时,你的建议通常效果很好。我在问题中犯了一个错误,说它被解读为字符串。现在,我编辑了那个部分。使用peewee时问题仍然存在