Human Date

Discussion in 'C#' started by moiseszaragoza, Sep 1, 2009.

  1. #1
    Well i have a date field in the DB and it works fine, but it hold the info in a way that is not really human readable.

    I need to make my date to be human readable to display on my site

    my out put is 2009-09-01 (yyyy-mm-dd) and i would like it to be Sep-01-09 if that is possible

    Thanks for all the help
     
    moiseszaragoza, Sep 1, 2009 IP
  2. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you using Classic ASP or ASP.net for the programming language?
     
    nyxano, Sep 1, 2009 IP
  3. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The only way I know how in Classic ASP is to create a function. I don't think there is a built in function to format the date the way you want. However, this function should work.

    <%
    Function HumanDate(thedate)
    
      DD = Day(thedate)
      MM = Month(thedate)
      YY = right(Year(thedate),2)
      
      if MM = "1" OR MM = "01" then MM = "Jan"
      if MM = "2" OR MM = "02" then MM = "Feb"
      if MM = "3" OR MM = "03" then MM = "Mar"
      if MM = "4" OR MM = "04" then MM = "Apr"
      if MM = "5" OR MM = "05" then MM = "May"
      if MM = "6" OR MM = "06" then MM = "Jun"
      if MM = "7" OR MM = "07" then MM = "Jul"
      if MM = "8" OR MM = "08" then MM = "Aug"
      if MM = "9" OR MM = "09" then MM = "Sep"
      if MM = "10" then MM = "Oct"
      if MM = "11" then MM = "Nov"
      if MM = "12" then MM = "Dec"
      
      HumanDate = MM & "-" & DD & "-" & YY
    End Function
    %>
    
    <% Response.Write HumanDate("2009-08-30") %>
    
    Code (markup):
    If you want a four digit year, just replace right(Year(thedate),2) with Year(thedate)

    Then, any place you want the Date to appear, just call upon HumanDate(datehere) and it will reformat the date for you.
     
    nyxano, Sep 1, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    camjohnson95, Sep 1, 2009 IP