forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeStampSQL.ahk
62 lines (43 loc) · 1.46 KB
/
TimeStampSQL.ahk
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
TimeStampSQL(fnAhkTimeStamp := "",fnIncludeT := 0)
{
; converts an AHK timestamp to an SQL timestamp
; MsgBox fnAhkTimeStamp: %fnAhkTimeStamp%`nfnIncludeT: %fnIncludeT%
; declare local, global, static variables
Try
{
; set default return value
SQLTimeStamp := ""
; validate parameters
If (fnAhkTimeStamp = "")
Throw, Exception("fnAhkTimeStamp was empty")
If fnAhkTimeStamp is not time
Throw, Exception("fnAhkTimeStamp is not time")
If (StrLen(fnAhkTimeStamp) > 14)
Throw, Exception("fnAhkTimeStamp was longer that 14 characters")
; initialise variables
; format timestamp
DefaultTimestamp := "20000101000000"
fnAhkTimeStamp := fnAhkTimeStamp SubStr(DefaultTimestamp,StrLen(fnAhkTimeStamp)-13)
FormatTime, ThisYear , %fnAhkTimeStamp%, yyyy
FormatTime, ThisMonth , %fnAhkTimeStamp%, MM
FormatTime, ThisDay , %fnAhkTimeStamp%, dd
FormatTime, ThisHour , %fnAhkTimeStamp%, HH
FormatTime, ThisMinute, %fnAhkTimeStamp%, mm
FormatTime, ThisSecond, %fnAhkTimeStamp%, ss
SQLTimeStamp := ThisYear "-" ThisMonth "-" ThisDay (fnIncludeT ? "T" : " ") ThisHour ":" ThisMinute ":" ThisSecond
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return SQLTimeStamp
}
/* ; testing
SomeTimeStamp := "201505161124"
ReturnValue := TimeStampSQL(SomeTimeStamp,0)
MsgBox, TimeStampSQL`n`nReturnValue: %ReturnValue%
*/