-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixdate.py
More file actions
37 lines (29 loc) · 804 Bytes
/
fixdate.py
File metadata and controls
37 lines (29 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#
# https://github.com/Jumaily
# Python 3
#
import sqlite3
import datetime
from time import gmtime, strftime
conn = sqlite3.connect('salaries.db')
c = conn.cursor()
rows = c.execute("SELECT id,hire_date FROM salaries").fetchall()
for row in rows:
dbid = row[0]
dbdate = str(row[1])
# some dates are empty, make sure there is a value.
if dbdate:
ndate = dbdate.split('/')
yr = int(ndate[2])
mo = ndate[0]
dy = ndate[1]
cyr = int(strftime("%y", gmtime()))
if yr<=cyr: yr+=2000
else: yr+=1900
newdate = (str(yr) +"-"+ mo +"-"+ dy)
c.execute('''UPDATE salaries SET datehire=? WHERE id=?''', (newdate,dbid))
# Save Changes to DB
conn.commit()
# for debuggin
# print("Updating row: ", dbid)
conn.close()