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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED DATE TO FORMAT MMDDYY

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
I have a value for my date field.

Examples:
7/23/2004
10/11/2004
11/9/2004

When I save these values to the database I would like them to be converted to the following before being inserted:

Was: Now:
7/23/2004 072304
10/11/2004 101104
11/9/2004 110994


Is this possible? And how? Thanks
 
You could simply concatenate the values together from Day(date), Month(date), Year(date)...odd, actually it looks like your doing mmddyy...same difference. The only necessary adition at that point would be a ZeroFill function, perhaps something like:
Code:
Function DateToString(myDate)
   Dim dd, mm, yy
   dd = ZeroFill(Day(myDate),2)
   mm = ZeroFill(Month(myDate),2)
   yy = ZeroFill(Right(Year(myDate),2),2)

   DateToString = mm & dd & yy
End Function

Function ZeroFill(numStr, numChars)
   If len(numStr) >= numChars Then
      ZeroFill = numStr
   Else
      ZeroFill = String(numChars - len(numStr),"0") & numStr
   End If
End Function

Might be a better way to do it, but that should get you from a to b,

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
What's the best way to call this function?

I have my textbox called PaymentDate and the value is 7/25/2004. is there a way to call the function with the onBlur and store the new value in a hidden textbox?
 
Nope, ASP code is all server-side, texxtboxes and events are client-side. You could write a <script> block to do this with either client-side javascript or client-side VBScript, but with ASP you would put the function in the page that one is submitting to and execute the function on the value that was POST'd back from the client.
In this case you would want to execute it like so (on the next page):
newDate = DateToString(Request.Form("PaymentDate"))

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
How can we do it in a DOS script to get the output in 'DD/MMM/YYYY'
 
I don't know about a DOS script, do you mean in a vbs script?

That function above should work exactly the same in a vbs script, you would just have to call it with the date you wanted to convert.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top