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

dateStamp - is there a better way

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
On the fly converting: 10/09/2006 to 2006-09-01
i need to take into consideration padding "0"
this is what i have, is there a smarter way?


function GDSdates(reform)
Dim reform1, reform2, reform3
reform1 = right("0" & month(reform),2)
reform2 = right("0" & day(reform),2)
reform3 = year(reform) & "-" & reform1 & "-" & reform2
GDSdates= reform3
end function
 
Maybe there is a smarter way but I dont know it. I think you just must add logic to check that the number is less than 10, if yes, then pad with zero.
Code:
If month(reform) < 10 Then 
  reform1  = "0" & month(reform)
Else
  reform1  = month(reform)
End If

Or devise a clever way to use string manipulation to achieve the same thing in one line of code. As you did.

 
The only way you could possibly shorten it would be to concatenate that all into a single line. Unfortunatly there is no simple formatting function that can be used in this case.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top