Skip to main content
Known Participant
November 17, 2010
Question

DateDiff():well cfml code is correct

  • November 17, 2010
  • 3 replies
  • 780 views

<cfset today = DateDiff("s", Now()+9*60*60, CreateDate(1970,1,1)) />

this is correct way get the seconds from unix time...?

I tried put this number [today] in database(MySQL) and appear with PHP but shows..21:40 Thu 08 Jul 1976 time, well?

php:

    if ($LastVisitDate1==NULL) { $LastVisitDate = "NOT SETUP"; } else { $LastVisitDate = date("H:i D d M Y", $LastVisitDate1); }

<?=$LastVisitDate  ?>

well cfml code is correct?

Message was edited by: 123polis123

This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
November 21, 2010

<cfset todayDatePlus9hours = dateadd("h",9,now())>
<cfset secondsSince1970 = DateDiff("s", createDatetime(1970,1,1,0,0,0), todayDatePlus9hours) >
<cfoutput>#secondsSince1970#</cfoutput>

Inspiring
November 17, 2010

Your cfml code is not correct.  First, you have the two dates in the wrong order.  Second, the extra math is giving you an incorrect answer.

Known Participant
November 17, 2010

<cfset today = DateDiff("s", CreateDate(1970,1,1), Now()) />

well this is correct? what if I want add to server time 9hours?

do you know any ready made script/component, cfml or php, that get visitors country by IP?

for administrative statistics.....

Owainnorth
Inspiring
November 17, 2010

Have you tried Googling for "visitors country by IP coldfusion"? Brings up some pretty promising links.

So you want to add to a date? How about dateAdd()? It's all in the docs hidden under Functions | Date and Time functions.

Inspiring
November 17, 2010

What data type is the column in the DB?  Why are you trying to store a date as "seconds from the unix epoch" rather than just as a date.  If you store it as a date, it'll work in all of CF, MySQL & PHP without any arsing around.

--

Adam

Known Participant
November 17, 2010
bigint(20)