Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- ColdFusion
- >
- Days since 1900 UTC - Works via DayOfWeek(x) but d...

Highlighted

Explorer
,

Sep 29, 2016

Copy link to clipboard

Copied

The code below gives the number of days since Januayr 1, 1900. I have no idea why this works. Please help. ALSO, does this work in CF10/2016 ???

Today is 9/29/16 so the number should be: 42640

THANKS!

<CFOUTPUT>

<CFSET DateVar = createDate( year(now()),month(now()),day(now()) )>

<CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>

days since 1/1/1900 = #DaysSince1900#<HR>

</CFOUTPUT>

Adobe Community Professional

DaveF67 wrote:

<CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>

There is nothing particular about dayOfWeek(x) in this formula. In fact, you will get the same result if you use

<cfset daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)>

where abracadabra is equal to any value. That is because

daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)

= DateVar - abracadabra - 1 + abracadabra -1

= DateVar - 2,

as the -abracadabra and +abracadabra cancel out.

Therefore, your code, <CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>, is equivalent to

<CFSET DaysSince1900 = DateVar-2>

It is well known that when you add a number to or subtract a number from a date, Coldfusion casts the result into the number of days since Coldfusion's zero date. For example,

<cfoutput>#now()+0#</cfoutput>

Coldfusion's zero date is 12 A.M. December 30, 1899. So what you have just output is the difference in days from the zero date until now.

You will have noticed that your initial date, 1/1/1900, is 2 days after Coldfusion's zero date. Hence all the code in your post is equivalent to

<cfoutput>#int(now() - 2)#</cfoutput>

TOPICS

Getting started

Community Guidelines

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

Explorer
,

Sep 29, 2016

Copy link to clipboard

Copied

The code below gives the number of days since Januayr 1, 1900. I have no idea why this works. Please help. ALSO, does this work in CF10/2016 ???

Today is 9/29/16 so the number should be: 42640

THANKS!

<CFOUTPUT>

<CFSET DateVar = createDate( year(now()),month(now()),day(now()) )>

<CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>

days since 1/1/1900 = #DaysSince1900#<HR>

</CFOUTPUT>

Adobe Community Professional

DaveF67 wrote:

<CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>

There is nothing particular about dayOfWeek(x) in this formula. In fact, you will get the same result if you use

<cfset daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)>

where abracadabra is equal to any value. That is because

daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)

= DateVar - abracadabra - 1 + abracadabra -1

= DateVar - 2,

as the -abracadabra and +abracadabra cancel out.

Therefore, your code, <CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>, is equivalent to

<CFSET DaysSince1900 = DateVar-2>

It is well known that when you add a number to or subtract a number from a date, Coldfusion casts the result into the number of days since Coldfusion's zero date. For example,

<cfoutput>#now()+0#</cfoutput>

Coldfusion's zero date is 12 A.M. December 30, 1899. So what you have just output is the difference in days from the zero date until now.

You will have noticed that your initial date, 1/1/1900, is 2 days after Coldfusion's zero date. Hence all the code in your post is equivalent to

<cfoutput>#int(now() - 2)#</cfoutput>

TOPICS

Getting started

Community Guidelines

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

DaveF67

Sep 29, 2016
0
/t5/coldfusion/days-since-1900-utc-works-via-dayofweek-x-but-dont-know-why/td-p/8565137
1
Reply
1

Correct answer by
BKBK
LATEST

Adobe Community Professional
,

Sep 29, 2016

Copy link to clipboard

Copied

DaveF67 wrote:

<CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>

There is nothing particular about dayOfWeek(x) in this formula. In fact, you will get the same result if you use

<cfset daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)>

where abracadabra is equal to any value. That is because

daysSince1900 = (DateVar-abracadabra-1) + (abracadabra-1)

= DateVar - abracadabra - 1 + abracadabra -1

= DateVar - 2,

as the -abracadabra and +abracadabra cancel out.

Therefore, your code, <CFSET DaysSince1900 = (DateVar-DayOfWeek(DateVar)-1) + (DayOfWeek(DateVar)-1)>, is equivalent to

<CFSET DaysSince1900 = DateVar-2>

It is well known that when you add a number to or subtract a number from a date, Coldfusion casts the result into the number of days since Coldfusion's zero date. For example,

<cfoutput>#now()+0#</cfoutput>

Coldfusion's zero date is 12 A.M. December 30, 1899. So what you have just output is the difference in days from the zero date until now.

You will have noticed that your initial date, 1/1/1900, is 2 days after Coldfusion's zero date. Hence all the code in your post is equivalent to

<cfoutput>#int(now() - 2)#</cfoutput>

Community Guidelines

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

Reply

Loading...

BKBK

Sep 29, 2016
1
/t5/coldfusion/days-since-1900-utc-works-via-dayofweek-x-but-dont-know-why/m-p/8565138#M174146
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.