• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using "DatTimeFormat" on my cfhttp page?

Contributor ,
Aug 18, 2015 Aug 18, 2015

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.

2015-08-18_1227.png

Here is the online link to image: http://screencast.com/t/MKYrH1Lkp

Views

877

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Aug 18, 2015 Aug 18, 2015

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.

Votes

Translate

Translate
LEGEND ,
Aug 18, 2015 Aug 18, 2015

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

Thanks for the help.. but still getting:
Capture.JPG

Here is my page:

2015-08-18_1423.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

What version of CF are you using?  #DateTimeFormat()# was only added in CF10.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

Ah.. I'm using CF9.. any alternative for me?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

You can just use two separate functions: dateFormat(now(), "yyyy-mm-dd") and timeFormat(now(),"hh:mm:ss")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 18, 2015 Aug 18, 2015

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..)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 18, 2015 Aug 18, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

LATEST

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation