Copy link to clipboard
Copied
I have the following working page but not sure how to add in a DateTimeFormat function?
Here is my current page and what I tried, but get error: Variable DATETIMEFORMAT is undefined.
Here is the online link to image: http://screencast.com/t/MKYrH1Lkp
Ok, I have the working Time & Date finally!
<cfset theDate = #DateFormat(DateAdd('d', -60, now()),'yyyy-mm-dd')# & "-" & #TimeFormat(now(), "hh.mm.ss")#>
cfdump gives me the correct date & time: 2015-06-19-04.51.50
Thanks for the help.
Copy link to clipboard
Copied
On line 10, remove the "," and replace it with a space (DateTimeFormat takes three arguments - date/time, mask, and timezone; the last two are optional.)
On line 27, surround your variable name with hashtags - #theDate#, not theDate.
HTH,
^_^
Copy link to clipboard
Copied
Thanks for the help.. but still getting:
Here is my page:
Copy link to clipboard
Copied
What version of CF are you using? #DateTimeFormat()# was only added in CF10.
Copy link to clipboard
Copied
Ah.. I'm using CF9.. any alternative for me?
Copy link to clipboard
Copied
You can just use two separate functions: dateFormat(now(), "yyyy-mm-dd") and timeFormat(now(),"hh:mm:ss")
Copy link to clipboard
Copied
Getting closer.. but I need Date & Time (-60 days) in this format: 2015-06-01-00.00.00
I tried: <cfset theDate = #DateFormat(DateAdd('d', -60, now()),'yyyy-mm-dd')#-#TimeFormat(now(), "hh.mm.ss")#>
cfdump gives me: 24168
If I try: <cfset theDate = #DateFormat(DateAdd('d', -60, now()),'yyyy-mm-dd')#>
cfdump gives me:2011-06-19 (just need the time added..)
Copy link to clipboard
Copied
Ok, I have the working Time & Date finally!
<cfset theDate = #DateFormat(DateAdd('d', -60, now()),'yyyy-mm-dd')# & "-" & #TimeFormat(now(), "hh.mm.ss")#>
cfdump gives me the correct date & time: 2015-06-19-04.51.50
Thanks for the help.
Copy link to clipboard
Copied
Unless you are displaying variable results within a string or directly on a page (ie, you're just setting the value), you don't need the hash marks around CF variables.
<cfset theDate = DateFormat(DateAdd('d', -60, now()),'yyyy-mm-dd') & "-" & TimeFormat(now(), "hh.mm.ss")>
I've not researched it, but I've heard that using hashtags around variables when setting values will slow it down. IDK. But they do tend to clutter code, so unless necessary, I don't use them.
Glad you got it fixed.
HTH,
^_^