vinhngba2704 commited on
Commit
bbc5359
·
1 Parent(s): 5654237

Add format_date function to format the string date

Browse files
Files changed (1) hide show
  1. modules/formatting.py +17 -0
modules/formatting.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ from dateutil import parser
3
+
4
+ # Function to format the date
5
+ def format_date(date_str):
6
+ try:
7
+ # Use dateutil.parser to automatically parse date string
8
+ raw_order_date = parser.parse(date_str)
9
+
10
+ # Format the datetime object into dd/mm/yyyy
11
+ return raw_order_date.strftime("%d/%m/%Y")
12
+
13
+ except Exception as e:
14
+ print(f"Failed to parse date '{date_str}': {e}")
15
+
16
+ # If parsing fail, return the original date string
17
+ return date_str