Home > Enterprise >  How to convert the datetime format to jalali date in list of dictionaries
How to convert the datetime format to jalali date in list of dictionaries

Time:07-28

How to iterate through and convert the DateTime in a list of dictionaries to Jalali date format. something like this

list_1 = [{'id': 103, **'date': '2022-07-21'**, 'a_name':'Account Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'},{'id': 103, **'date': '2022-07-25'**, 'a_name':'Account 
Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'},{'id': 103, **'date': '2022-07-28'**, 'a_name':'Account 
 Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'}]

to

list_2 = [{'id': 103, **'date': '1401-05-27'**, 'a_name':'Account Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'},{'id': 103, **'date': '1401-05-31'**, 'a_name':'Account 
Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'},{'id': 103, **'date': '1401-03-02'**, 'a_name':'Account 
 Receivable', 'ref': None, 
'move_name': 'INV/2022/0012'}]

CodePudding user response:

I think, you have an error in the converting of dates. For example, the date 2022-07-21 will not be 1401-05-27, but 1401-04-30 (Correct me, if I'm wrong

  • Related