Dates! Dates! Dates!

Discussion in 'ASP General' started by PW, Aug 7, 2004.

  1. PW

    PW Guest

    <rant>

    Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the
    butt! I seem to get caught out so many times. I realise its my own fault,
    but going from the posts in this newsgroup and others, I'm not the only one.
    Its just a poorly addressed issue within ASP. So for all your poor buggers
    out there that are having problems, particularly with european date formats,
    here is my solution.

    I have the user enter their date in european format ("31-12-2004") and then
    handle it this way ...

    myDate = Request.QueryString("txtDate")
    myArray = Split(myDate, "-")
    myDD = myArray(0)
    myMM = myArray(1)
    myYYYY = myArray(2)
    myISOdate = myYYYY & "-" & myMM & "-" & myDD

    I find that ISO formatted dates typically go into the database of choice
    pretty readily.

    Hope this helps someone.

    Cheers,
    PW

    </rant>
    PW, Aug 7, 2004
    #1
    1. Advertising

  2. PW

    Evertjan. Guest

    PW wrote on 07 aug 2004 in microsoft.public.inetserver.asp.general:
    > I have the user enter their date in european format ("31-12-2004") and
    > then handle it this way ...
    >
    > myDate = Request.QueryString("txtDate")
    > myArray = Split(myDate, "-")
    > myDD = myArray(0)
    > myMM = myArray(1)
    > myYYYY = myArray(2)
    > myISOdate = myYYYY & "-" & myMM & "-" & myDD


    Usually I also allow for YY, the . and the /, so:

    function myISOdate(d)
    d = trim(d)
    d = replace(d,".","-")
    d = replace(d,"/","-")
    a = Split(d,"-")
    if len(a(2))=2 then a(2) = "20" & a(2)
    myISOdate = a(2) & "-" & a(1) & "-" & a(0)
    end function

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 7, 2004
    #2
    1. Advertising

  3. PW

    PW Guest

    "Evertjan." <> wrote in message
    news:Xns953E64970D1A0eejj99@194.109.133.29...
    >
    > Usually I also allow for YY, the . and the /, so:
    >
    > function myISOdate(d)
    > d = trim(d)
    > d = replace(d,".","-")
    > d = replace(d,"/","-")
    > a = Split(d,"-")
    > if len(a(2))=2 then a(2) = "20" & a(2)
    > myISOdate = a(2) & "-" & a(1) & "-" & a(0)
    > end function



    Hmmm, thats a good idea, except for if the user enters something like
    "20/01/60" in which 60 become 2060 insted of 1960.
    But I will incorporate that change, thanks. :)
    PW, Aug 8, 2004
    #3
  4. PW

    Evertjan. Guest

    PW wrote on 08 aug 2004 in microsoft.public.inetserver.asp.general:
    >> if len(a(2))=2 then a(2) = "20" & a(2)

    >
    > Hmmm, thats a good idea, except for if the user enters something like
    > "20/01/60" in which 60 become 2060 insted of 1960.


    if you want to define that for say 2009/1910:

    if len(a(2))=2 and +a(2)<10 then
    a(2) = "20" & a(2)
    elseif len(a(2))=2 and +a(2)>=10 then
    a(2) = "19" & a(2)
    end if


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 8, 2004
    #4
  5. PW

    Mark Schupp Guest

    It's really not an "ASP" problem. The same issues come up in any programming
    environment where the person entering the dates may use a different format
    than the system storing the dates. We finally gave up on manually entered
    text dates in our system and now use a popup date calendar that always sends
    the dates to the web server as "yyyymmdd hh:mm:ss",

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "PW" <> wrote in message
    news:...
    >
    > <rant>
    >
    > Sorry guys, but I just have to whinge. Dates in ASP are a total pain in

    the
    > butt! I seem to get caught out so many times. I realise its my own

    fault,
    > but going from the posts in this newsgroup and others, I'm not the only

    one.
    > Its just a poorly addressed issue within ASP. So for all your poor

    buggers
    > out there that are having problems, particularly with european date

    formats,
    > here is my solution.
    >
    > I have the user enter their date in european format ("31-12-2004") and

    then
    > handle it this way ...
    >
    > myDate = Request.QueryString("txtDate")
    > myArray = Split(myDate, "-")
    > myDD = myArray(0)
    > myMM = myArray(1)
    > myYYYY = myArray(2)
    > myISOdate = myYYYY & "-" & myMM & "-" & myDD
    >
    > I find that ISO formatted dates typically go into the database of choice
    > pretty readily.
    >
    > Hope this helps someone.
    >
    > Cheers,
    > PW
    >
    > </rant>
    >
    >
    Mark Schupp, Aug 9, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dilbert Does Dallas

    Release Dates

    Dilbert Does Dallas, Mar 24, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    534
    james
    Mar 26, 2005
  2. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    859
    Rob Schieber
    Sep 30, 2005
  3. Replies:
    1
    Views:
    205
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    195
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    159
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page