Created
August 25, 2022 15:45
-
-
Save trycf/7f816710392e7013d39e66b36af85711 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
public function fixMyDate(any dateToFix){ | |
writeOutput("Starting with : #mytimeObj#" & "<br />"); | |
try { | |
var dateToSave = arguments.dateToFix.parseDateTime(); | |
} catch (any e) { | |
// parseDateTime() failed because - I am already a dateTime Object! | |
var dateToSave = arguments.dateToFix; | |
} | |
return dateToSave; | |
} | |
//Start with a TS object like Lucee gives you | |
mytimeObj = createDateTime(2022, 08, 25, 06, 30, 00); | |
// run the function that works regardless of ACF of Lucee | |
myResult = fixMyDate(mytimeObj); | |
writeOutput("insert into myTable (theTSColumn) values ('#dateTimeFormat(myResult, 'YYYY-MM-dd HH:nn:ss')#')" & "<br /><br />"); | |
// Start with a string like you get from ACF | |
mytimeObj = "2022-08-25 06:30:00.0"; | |
// run the Same function that works regardless of ACF of Lucee | |
myResult = fixMyDate(mytimeObj); | |
writeOutput("insert into myTable (theTSColumn) values ('#dateTimeFormat(myResult, 'YYYY-MM-dd HH:nn:ss')#')" & "<br />"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment