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

Textbox and Date formatting

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
GB
Hi

Can anyone help me.....I've got a textbox where a user can enter a date. I want to reformat it to "dd-MMM-yyyy" when the user clicks on a button. I can't seem to get this to work. I've tried Textbox.text = format(Textbox.text, "{0:dd-MMM-yyyy]") which didn't work.

Please help!
Cheers
Lbob
 
Wait, you want to do this in the browser? Ie, before it sent to the server? That would be client-side scripting, you may wnt to try the VBScript or Javascript forums:
VBScript: forum329
Javascript: forum216

-T


barcode_1.gif
 
and why MMM???

Known is handfull, Unknown is worldfull
 
If you did want to do this server-side, ie on the page processing your form, you could do something like:
Code:
Dim enteredDate, formattedDate
enteredDate = Request.Form("yourTextInputName")
If isDate(enteredDate) Then
   enteredDate = cDate(enteredDate)
Else
   Response.Write "Error - Not A Date"
End If

If Day(enteredDate) < 10 Then
   formattedDate = "0" & Day(enteredDate)
Else
   formattedDate = Day(enteredDate)
End If

formattedDate = formattedDate & "-" & Left(MonthName(Month(enteredDate)),3) & "-" & Year(enteredDate)

This could easily be built as a function, like so:
Code:
Function FormatMyDate(aDate)
   If Day(aDate) < 10 Then
      FormatMyDate= "0" & Day(aDate)
   Else
      FormatMyDate= Day(aDate)
   End If

   FormatMyDate= formattedDate & "-" & Left(MonthName(Month(aDate)),3) & "-" & Year(aDate)
End Function

'then to call it
If isDate(Request.Form("YourTextInput")) Then
   Response.Write FormatMyDate(cDate(Request.Form("YourTextInput")))
Else
   Response.Write "That Was Not A Date!"
End if

As I said earlier though, it sounds like you want to do this client-side, which means you will need to use client-side scripting like VBScript or javascript to get the job done.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top