-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_month_to_num.py
More file actions
66 lines (64 loc) · 1.37 KB
/
date_month_to_num.py
File metadata and controls
66 lines (64 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def month_to_num(input):
input = input.lower()
if input == "jan" or input == "january":
return 1
elif input == "feb" or input == "february":
return 2
elif input == "mar" or input == "march":
return 3
elif input == "apr" or input == "april":
return 4
elif input == "may":
return 5
elif input == "jun" or input == "june":
return 6
elif input == "jul" or input == "july":
return 7
elif input == "aug" or input == "august":
return 8
elif input == "sep" or input == "september":
return 9
elif input == "oct" or input == "october":
return 10
elif input == "nov" or input == "november":
return 11
elif input == "dev" or input == "december":
return 12
else:
print input, "== not a valid month"
return -1
def num_to_month_short(input):
try:
input = int(input)
if input == 1:
return "jan"
elif input == 2:
return "feb"
elif input == 3:
return "mar"
elif input == 4:
return "apr"
elif input == 5:
return "may"
elif input == 6:
return "jun"
elif input == 7:
return "jul"
elif input == 8:
return "aug"
elif input == 9:
return "sep"
elif input == 10:
return "oct"
elif input == 11:
return "nov"
elif input == 12:
return "dec"
else:
print input, "== not a valid month!"
return "INVALID"
except:
print "INVALID MONTH"
#TESTS:
print "June:", month_to_num("jun")
print "6:" , num_to_month_short(6)