Format a date to work with MySQL date, datetime, time and timestamp data types

time:sql(STRING $time="now")

$x = time:now()
#=> "2020-12-29 02:17:23.977554 UTC"

time:sql($x)
#=> "2020-12-29 02:17:35"

# note: this function automatically transforms the given time to UTC
time:sql("2020-01-06 04:17:43.065242 EST")
#=> "2020-01-06 09:17:43"

# note: if time is already UTC, it won't be changed
time:sql("2020-01-06 04:17:43.065242 UTC")
#=> "2020-01-06 04:17:43"

# note: if timezone is missing in the time string, it is considered to be UTC
time:sql("2020-01-06 04:17:43.065242")
#=> "2020-01-06 04:17:43"

Copyright ©2013-2022 SunSed®. All rights reserved.