Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trycf/7f816710392e7013d39e66b36af85711 to your computer and use it in GitHub Desktop.
Save trycf/7f816710392e7013d39e66b36af85711 to your computer and use it in GitHub Desktop.
TryCF Gist
<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