Skip to main content
January 30, 2012
Question

Passing a date/time in a URL

  • January 30, 2012
  • 2 replies
  • 2826 views

What is the safest way to pass a date/time value in a URL?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    January 31, 2012

    centricCD wrote:

    What is the safest way to pass a date/time value in a URL?

    I would pass it exactly as-is. Unless I see otherwise, I trust latest versions of browsers and of ColdFusion to be able to sort it out between themselves.

    Don't take my word for it. Do the following test.

    Turn on debugging in the Administrator. Run the following code as a CFM page.

    <!--- This time tomorrow--->

    <cfset testDate = dateAdd("d","1",now())>

    <cfif isDefined("url.dt")>

        <cfoutput>      

            The test date is this time tomorrow: #url.dt# (unformatted).<br>

            Formatted: #dateFormat(url.dt,"dd/mm/yyyy")# #timeFormat(url.dt,"hh:mm:ss")#       

        </cfoutput>

    </cfif>

    <cfform method="get">

    <cfinput name="dt" type="text" value="#testDate#">   

    <cfinput name="sbmt" type="submit" value="Send">   

    </cfform>

    To get an idea what is going on, observe the following, besides the output:

    • In the address field of the browser: the query-string after you press the Send button;
    • In the debugging information at the bottom of the page: the value of the CGI variable QUERY_STRING and the URL Parameters.
    Inspiring
    January 30, 2012

    Safe from what?

    January 30, 2012

    invalid characters. I have seen dates converted to numbers before. Can CF do this?

    Inspiring
    January 30, 2012

    Use DateFormat and TimeFormat to create a string in the format you want and urlencodedformat to handle any spaces.  On the page that receives this, use parsedatetime to convert the string into a datetime object.