format date

Hi.. Can anybody tell me how can I format my datetime object like eg  1-Jan-2013
kpankaj9Asked:
Who is Participating?
 
GawaiConnect With a Mentor Commented:
no above date will not work. and this one will surely does wat u are expecting

Dim d As New Date

d = d.Now

''Response.Write(d.ToShortDateString)
Response.Write("<BR>" & Format(d, "dd-MMM-yyyy"))
0
 
MorcalavinCommented:
If this is classic asp, it has a function called formatdatetime
Response.Write FormatDateTime(Now(), 0)

0 could be 0-4, depending on the format you want.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
kpankaj9Author Commented:
Hey Gawai
Thanks for response. I m using ASP.Net 1.1/C# and there I could not use ur code.Can you pls help.

Thanks
0
 
GawaiCommented:
i guess u did not try my code

Function FormatMediumDate(DateValue)
    Dim strYYYY
    Dim strMM
    Dim strDD


      strYYYY = CStr(DatePart("yyyy", DateValue))
      strMM = CStr(DatePart("m", DateValue))
      If Len(strMM) = 1 Then strMM = "0" & strMM

      strDD = CStr(DatePart("d", DateValue))
      If Len(strDD) = 1 Then strDD = "0" & strDD

      FormatMediumDate = strDD& "-" & strMM & "-" & strYYYY
End Function

now u can use above function like...

FormatMediumDate(date())
0
 
Mass Dot NetCommented:
Here's a function I wrote recently that allows you to format a date in a variety of ways, including the delimiter character.  I've also included some sample code at the bottom, to illustrate how to use it.

=======================================================
<%      '// Here are the following date formatting characters:
            '//            * MMMM = Month name ("January")
            '//            * MMM = First three letters of month name ("Jan")
            '//            * MM = Two-digit month number ("01")
            '//            * %M = One-digit month number ("1")
            '//            * dddd = Weekday name ("Wednesday")
            '//            * dd = Two-digit day number ("05")
            '//            * %d = One-digit day number ("5")
            '//            * yyyy = Complete year number ("2007")
            '//            * yy = Two right-most digits of year number ("07")
            Function CustomFormatDate(sDate, sDateFormat)
            Dim sReturnValue, dtDate, M, MM, MMM, MMMM, d, dd, dddd, yy, yyyy

            sReturnValue = ""
           
            if IsDate(sDate) then
                  dtDate = cDate(sDate)
                  M = Month(dtDate)
                  MM = M:  if (M < 10) then MM = "0" & MM
                  MMM = Left(MonthName(M), 3)
                  MMMM = MonthName(M)
                  d = Day(dtDate)
                  dd = d:  if (d < 10) then dd = "0" & dd
                  dddd = WeekdayName(Weekday(dtDate))
                  yy = Right(CStr(Year(dtDate)), 2)
                  yyyy = Year(dtDate)

                  sReturnValue = sDateFormat
                  sReturnValue = Replace(sReturnValue, "MMMM", MMMM,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "MMM", MMM,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "MM", MM,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "%M", M,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "dddd", dddd,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "dd", dd,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "%d", d,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "yyyy", yyyy,1,-1,0)
                  sReturnValue = Replace(sReturnValue, "yy", yy,1,-1,0)
            end if

            CustomFormatDate = sReturnValue
      End Function

      Dim arrSampleDateFormats, dtSampleDate, iIndex, sSampleDateFormat, sFormattedDate
      arrSampleDateFormats = Array("%d-MMM-yyyy", "dd-MMM-yyyy", "MM/dd/yyyy", "MM.dd.yyyy", "MM-dd-yyyy", "dd/MM/yyyy", "dd.MM.yyyy", "dd-MM-yyyy", "dd/MMM/yy", "dd.MMM.yy", "dd-MMM-yy", "yyyy/MM/dd", "yyyy.MM.dd", "yyyy-MM-dd", "dddd, MMMM dd, yyyy", "MMMM dd, yyyy", "dddd, dd MMMM, yyyy", "dd MMMM, yyyy")
      dtSampleDate = CDate(#2007-09-01#) %>
     
     
      <div><font face="Courier" size="2">
            Sample Date = [<%=dtSampleDate%>]<br>
           
            <hr>

            <table width="100%">
<%      For iIndex = LBound(arrSampleDateFormats) to UBound(arrSampleDateFormats)
            sSampleDateFormat = arrSampleDateFormats(iIndex)
            sFormattedDate = CustomFormatDate(dtSampleDate, sSampleDateFormat) %>
                  <tr>
                        <td width="250"><%=sSampleDateFormat%></td>
                        <td><%=sFormattedDate%></td>
                  </tr>
<%      Next %>
            </table>
           
            <hr>
      </font></div>
=======================================================


-= DeathToSpam =-
0
 
GawaiCommented:
ah i missed...you need .net code
0
 
GawaiCommented:
just try this one

Format(Date, "dd-MMM-yyyy")
0
 
kpankaj9Author Commented:
hey gawai..
cant belive it.....
its just worked by writing dd-MMM-yyyy.......thanks a lot
accepted ur solution...:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.