Click to See Complete Forum and Search --> : How to add a leading zero to day and month format?


erick30
08-25-2005, 11:40 AM
I receive from the DB a date (sql smalldatetime format) broken in three parts (day, month and year. Each one in a different parameter). And once in the web app I want to use day and month with the format (01, 02, 03,.., 10, 11,..), I mean with a leading 0 if necessary, since now I receive day and month with the format (1, 2, 3,.., 10, 11). How can I format the received data?

Here a piece of the sub that receives the data:

strConnection.open()
CmdRecover.ExecuteNonQuery

If Not CmdRecover.Parameters("@day").Value Is DbNull.Value Then
day.SelectedValue = CmdRecover.Parameters("@day").Value
End If

If Not CmdRecover.Parameters("@month").Value Is DbNull.Value Then
month.SelectedValue = CmdRecover.Parameters("@month").Value
End If

If Not CmdRecover.Parameters("@year").Value Is DbNull.Value Then
year.Text() = CmdRecover.Parameters("@year").Value
End If



Thank you

erick30
08-26-2005, 04:48 AM
There is a function in VB that does this operation automatically!. So, the problem it' s solved.

gRoberts
09-09-2005, 11:38 AM
or you could use year.Text() = CmdRecover.Parameters("@year").Value.ToString("0000") which will turn 02 to 0200

but you get the idea.