15 Replies Latest reply on Dec 13, 2006 6:34 AM by Keith444

    convert time

    Keith444
      i am using a cfschedule to match the time and date in my database table with the Now() function to send out the sms which works fine.

      accept it matches the time and date with the server time and date not the time and date of the local area it was entered ie UK Australia etc


      my server is in australia, say if a user in the UK selects a time of '08:00:00' from a list box, before inserting into my database can i convert that somehow to what my server time would be ?
        • 1. Re: convert time
          Level 7
          Checkout the LS date and time functions, they may help.
          • 2. Re: convert time
            Keith444 Level 1
            ok yes i have tried that with the code below but it diplays the same time for each time zone

            any ideas?

            <cfloop LIST = "#Server.Coldfusion.SupportedLocales#"
            index = "locale" delimiters = ",">
            <cfset oldlocale = SetLocale(locale)>

            <cfoutput><p><B><I>#locale#</I></B><br>
            #LSTimeFormat(Now())#<br>
            #LSTimeFormat(Now(), 'hh:mm:ss')#<br>
            #LSTimeFormat(Now(), 'hh:mm:sst')#<br>
            #LSTimeFormat(Now(), 'hh:mm:sstt')#<br>
            #LSTimeFormat(Now(), 'HH:mm:ss')#<br>
            <hr noshade>
            </cfoutput>

            </cfloop>
            • 3. Re: convert time
              insuractive Level 3
              Unless you have some way to tie a user with a specific geographic area (such as a user profile, etc), I'm not sure coldfusion can tell what time zone a request is coming from. You could probably hack something together using the user's IP address, but a better solution might be to use JavaScript to set a hidden date field so that when the user submits the form you get the date associated with his/her machine.
              • 4. Re: convert time
                Keith444 Level 1
                ok i have worked out i need to do this

                <cfset localtime = '#form.SMS_Date# #form.SMS_Time#' + #info.utcTotalOffset#>

                but i need to convert my forms date and time into a date-time format how can i do this
                • 5. Re: convert time
                  Dan Bracuk Level 5
                  Among the functions you can use are:
                  createdate
                  createdatetime
                  createodbcdate
                  createodbcdatetime
                  dateformat
                  • 6. Re: convert time
                    Level 7
                    Keith444 wrote:
                    > ok i have worked out i need to do this
                    >
                    > <cfset localtime = '#form.SMS_Date# #form.SMS_Time#' + #info.utcTotalOffset#>
                    >
                    > but i need to convert my forms date and time into a date-time format how can i
                    > do this

                    you also need to take DST into consideration for both the server & the client.

                    • 7. Re: convert time
                      Keith444 Level 1
                      ok thanks, just getting one problem

                      <cfset info = GetTimeZoneInfo()>
                      <CFSET yourDate = CreateDateTime (form.year, form.month, form.day, form.hour, form.minute, form.second)>
                      <cfset localtime = #yourDate# + #info.utcHourOffset#>

                      <cfoutput>
                      Server Time = #localtime#
                      </cfoutput>

                      but instead of showing the time it shows this number 35944.675

                      any ideas
                      • 8. Re: convert time
                        Level 7
                        Keith444 wrote:
                        > ok thanks, just getting one problem
                        >
                        > <cfset info = GetTimeZoneInfo()>
                        > <CFSET yourDate = CreateDateTime (form.year, form.month, form.day, form.hour,
                        > form.minute, form.second)>
                        > <cfset localtime = #yourDate# + #info.utcHourOffset#>
                        >
                        > <cfoutput>
                        > Server Time = #localtime#
                        > </cfoutput>
                        >
                        > but instead of showing the time it shows this number 35944.675

                        that's decimal days since the start of cf epoch (13-dec-1899). you want dateAdd
                        method.

                        dateAdd("h",info.utcHourOffset,CreateDateTime (form.year, form.month,
                        form.day,form.hour,form.minute, form.second))

                        and again you're not accounting for DST differences.
                        • 9. Re: convert time
                          Keith444 Level 1
                          ok many thanks for that, i thought the GetTimeZoneInfo() get the local time of the users computer so would that not include DST?

                          if not how would i get DST?

                          • 10. Re: convert time
                            Level 7
                            Keith444 wrote:
                            > ok many thanks for that, i thought the GetTimeZoneInfo() get the local time
                            > of the users computer so would that not include DST?

                            server side.

                            > if not how would i get DST?

                            simplest to ask them for their timezone (tz) or maybe give them the choice when
                            they schedule the task. if you know their country & can use the icu4j lib you
                            can get tz by country from it, well a set of tz anyway.
                            • 11. Re: convert time
                              Keith444 Level 1
                              ok thanks

                              so if i get the user to select from a list box the timezone how do i populate the list box to have a value of there tz?
                              • 12. Re: convert time
                                Level 7
                                Keith444 wrote:
                                > so if i get the user to select from a list box the timezone how do i populate
                                > the list box to have a value of there tz?

                                http://www.sustainablegis.com/projects/tz/testTZCFC.cfm
                                • 13. Re: convert time
                                  Keith444 Level 1
                                  ok yes i see, just one more thing, i have in my table a column called datetime,

                                  say a user was in the UK and selects 08:00:00 as a time and 13/12/2006 as the date from my list boxes, from the tz column in my table how can i convert the selected time and date in the the tz of the server before in insert it to my table
                                  • 14. Re: convert time
                                    Level 7
                                    Keith444 wrote:
                                    > ok yes i see, just one more thing, i have in my table a column called datetime,
                                    >
                                    > say a user was in the UK and selects 08:00:00 as a time and 13/12/2006 as the
                                    > date from my list boxes, from the tz column in my table how can i convert the
                                    > selected time and date in the the tz of the server before in insert it to my
                                    > table

                                    if these are separate fields, build a datetime using createdate. "cast" that to
                                    UTC based on their tz. cast that UTC datetime to server time. the CFC's method
                                    will handle DST for you.

                                    • 15. convert time
                                      Keith444 Level 1
                                      hi i dont understand what you mean by cast? are there any code examples on what i need to do

                                      also how do i limit the values of the testTZCFC.cfm list box i only need a few time zones