以日期格式存储日期时间,使用Pymong存储Flask

2024-09-24 02:28:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用pymongo的Flask中,我希望在mongodb中以日期格式存储datetime,但是它使用我编写的代码以数组或字符串格式存储

myscript

date_post=time.strftime("%b %d %Y %H:%M:%S %p")  # if i store this in mongo 
                                             db it stores in string datatype
date_post=time.strptime(date_post,"%b %d %Y %H:%M:%S %p")
# if i store this in mongo db it stores in Array datatype
print(type(date_post))


jd = mongo.db.rest_create_job_add

job_id =jd.insert({'Country':country,'State':state,'City':city,'Spoc_Name':spoc_name,'Spoc_EMP_ID':spoc_empid,'SPOC_Email':spoc_email,'Spoc_Mobile_No':spoc_mobile,'Spoc_Work_or_Direct_No':spoc_workno,
    'date_posted':date_post,'band_range':band_range})

在mongodb中,它将date_posted存储在Array datatype中,而我需要它以日期格式存储。在

任何帮助将不胜感激

提前谢谢


Tags: storeindbdateiftimemongomongodb