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

date convert

Guest
Feb 28, 2007 Feb 28, 2007

Copy link to clipboard

Copied

hi i have a date and time field in my database which i need to convert from my server date and time to my users date and time, i have this working the oposite way already using a text form field,

i am just not sure how to alter the code to use my database field which displays as 2007-02-28 00:00:00
TOPICS
Advanced techniques

Views

498

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

LEGEND , Mar 01, 2007 Mar 01, 2007
JohnGree wrote:
> ok thanks but i am getting a error
>
> Variable DBDATETIMEOBJECT is undefined

place holder, put your real data in there.

Votes

Translate

Translate
LEGEND ,
Feb 28, 2007 Feb 28, 2007

Copy link to clipboard

Copied

JohnGree wrote:
> <cfscript>
> // or wherever you put the timezone CFC
> tz=createObject("component","timeZone");
> // assuming this is user's locale, you need to manage these
> setLocale("English (Australian)");
> smsDate=lsParseDateTime(form.InboxDate);
>
> hours=listFirst(SMS_Time,":")+listGetAt(SMS_Time,2,":")/60+listLast(SMS_Time,":"
> )/360;

not really sure what you're trying to do but maybe something like

hours=hour(SMS_Time)+(minute(SMS_Time)/60)+(second(SMS_Time)/360);

> smsDate=dateAdd("h",hours,smsDate);
> // shortcut method i forgot about
> serverDate=tz.castToServer(smsDate,GetUser.LocalTime12);
> </cfscript>

all this seems kind of familiar....

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
Guest
Feb 28, 2007 Feb 28, 2007

Copy link to clipboard

Copied

ok i have a date and time column in my database which is put there by the now() function, this is server time.


what i need to do is convert this server time back into my users time.

my users have a column called LocalTime12 which displays the time zones ie Australia/Sydney

so can i use this to change the time back into Australia/Sydney time and date

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 ,
Feb 28, 2007 Feb 28, 2007

Copy link to clipboard

Copied

JohnGree wrote:
> so can i use this to change the time back into Australia/Sydney time and date

first, don't do any date math on those datetime objects. after you get them back
from the db,

<cfscript>
userTZ="Australia/Sydney"; // or whatever tz ID you need
tz=createObject("component","timeZone");
userDateTime=tz.castFromServer(dbDateTimeObject,userTZ);
</cfscript>

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
Guest
Mar 01, 2007 Mar 01, 2007

Copy link to clipboard

Copied

ok thanks but i am getting a error

Variable DBDATETIMEOBJECT is undefined

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 ,
Mar 01, 2007 Mar 01, 2007

Copy link to clipboard

Copied

LATEST
JohnGree wrote:
> ok thanks but i am getting a error
>
> Variable DBDATETIMEOBJECT is undefined

place holder, put your real data in there.

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