Link to home
Start Free TrialLog in
Avatar of dave_ie
dave_ie

asked on

DateTime conversion to String

hi

i have a problem (as always)

i have an access database field with a Date/Time field, now all i want to do is convert it to a string.

i retrive the value from the database with an
RS.Fields("post_date") statement etc. so how can i declare a variable string to hold the string representation of that datetime field ?????

can anyone help me ?????

if its any help heres my attempt at the asp code

<%                              
  Dim strDate
  strDate = String(Date(RS.Fields,"post_date")))',"dd/mm/yy")
  Response.Write(strDate)
%>

thanks in advance guys
dave
Avatar of GeoffKell
GeoffKell

Use FormatDateTime

<%                              
 Dim strDate
 strDate = FormatDate(now(),2)
 Response.Write(strDate)
%>



To see all possble formats run the following ASP script

   <html><head>
   <title>formatdates.asp</title>
   </head><body bgcolor="#FFFFFF"><html>
   <%'My ASP program that formats dates
   response.write "<hr>"
   for counter=0 to 4
      currentdate=now()
      response.write "today is..." & "<br>"
      response.write currentdate & "<P>"
      select case counter
      case 0
         whichformat="vbgeneraldate"
      case 1
         whichformat="vblongdate"
      case 2
         whichformat="vbshortdate"
      case 3
         whichformat="vblongtime"
      case 4
         whichformat="vbshorttime"
      end select
      response.write "FormatDate(now()," & whichformat & ")="
      response.write Formatdatetime(currentdate,counter) & "<P><HR>"
   next%>
   </body></html>

regards
GK
ASKER CERTIFIED SOLUTION
Avatar of Shane_OConnor
Shane_OConnor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually, I see what you need to do now. Try
datevar = day(rs("Post_Date")) & "/" & month(rs("Post_Date")) & "/" & right(Year(rs("Post_Date"),2)
strdate = CSTR(datevar)
response.write strdate
Should work....
Avatar of dave_ie

ASKER

thx a lot for that shane

dave