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

Formating dates in a VB application. 2

Status
Not open for further replies.

Tigerman

Programmer
May 15, 2001
18
US
I'm currently writing a program for my department that automatically inserts the date into a text field. The problem is that when the date is inserted, it is in a "m/d/yy" format. The problem is that a format of "mm/dd/yy" is required in order to work with our software. How can I customize the format of the date to what I need?
 
Here Ya Go

Code:
Dim sDate as String
sDate = FormatDate()

Public Function FormatDate() As String
    Dim sDate As String
    Dim sMonth As String, sDay As String, sYear As String
    sMonth = Month(Date)
    sDay = Day(Date)
    sYear = Year(Date)
    If Len(sMonth) < 2 Then sMonth = &quot;0&quot; & sMonth
    If Len(sDay) < 2 Then sDay = &quot;0&quot; & sDay
    If Len(sYear) > 2 Then sYear = Right(sYear, 2)
    sDate = sMonth & &quot;/&quot; & sDay & &quot;/&quot; & sYear
    FormatDate = sDate
End Function
 
Ha! Ha! I am feeling a bit lazy today. Thanks guys! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top