Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format ?

Status
Not open for further replies.

mdr2273

Programmer
Sep 4, 2006
22
US
How can I format the date 11/23/2006 to just show as 11/23?
 
try this:

Code:
dim mydate, intpos
mydate = "11/23/2006"
intpos = instrrev(mydate,"/")
response.write MID(mydate,1,intpos-1)

-DNG
 
Assuming that the month and date could be either 1 or 2 digits, I'd do it like this:
Code:
theDate = left(theDate,len(theDate)-5)

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I like those methods but I wanted to chime in that ASP has some truly fantastic date/time manipulation functions. I've used them to write some very well-developed calendar applications, and since dates are usually touchy to deal with I prefer to use the most reliable methods available. Lucky for me, I found a wonderful article from 4GuysFromRolla.com at


...which in one short page told me everything I needed to know.

I'm sure your question is simpler than this, and it's always difficult to effectively convert a string to a real date. If you visit the link above you'd be able to apply these techniques to create a custom formatted date in any manner you could dream up.

But, back to your situation :) This is the best method I came up with, which I don't think is perfect because it still relies on the date being formatted as month/day/year. This would, however, provide your application with the ability to manipulate the date or dates further with little effort.

Code:
mydate = "11/23/2006"
mydate = split(mydate,"/")
adate = DateSerial(mydate(2),mydate(0),mydate(1))
response.write Month(adate)&"/"&Day(adate)

As I said it still relies on the date being a certain format, but you could at least extend the delimiter capabilities by saying:

Code:
mydate = "11/23/2006"
' An array of all perceived possible delimiters
delims = Array("/","\","-",":",".")
for each thingiput in delims
   if instr(mydate,thingiput)>0 then
      strdelim=thingiput
      exit for
   end if
next
mydate = split(mydate,strdelim)
adate = DateSerial(mydate(2),mydate(0),mydate(1))
response.write Month(adate)&"/"&Day(adate)

I know this may be overkill for the situation but I find that my apps grow exponentially from the idea to the final product, so I hope this will come in handy some time.

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top