5 Replies Latest reply on Mar 1, 2007 12:59 AM by Newsgroup_User

    date convert

    JohnGree Level 1
      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
        • 1. Re: date convert
          Level 7
          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....
          • 2. Re: date convert
            JohnGree Level 1
            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
            • 3. Re: date convert
              Level 7
              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>

              • 4. Re: date convert
                JohnGree Level 1
                ok thanks but i am getting a error

                Variable DBDATETIMEOBJECT is undefined
                • 5. Re: date convert
                  Level 7
                  JohnGree wrote:
                  > ok thanks but i am getting a error
                  >
                  > Variable DBDATETIMEOBJECT is undefined

                  place holder, put your real data in there.