|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Date Formatting in VB Code
I have a sample code shown below which checks for certain dates and display appropriate messages. The codes shown below which are part of a software package will be installed in more than one computer with various date settings (dd-mm-yy, mm/dd/yy, etc.) To test the future, I have set the date settings on my computer to yyyy-mm-dd. I thought the Format function in the Code shown below will have the value for TodaysDate in the dd-mm-yy format. But, I am having the format in the yyyy-mm-dd format which is the computer's date setting. Can anyone please tell me how to have the date settings format for the variable TodaysDate in the dd-mm-yy format?
Code:
Dim TodaysDate As Date
TodaysDate = Format(Now, "dd-mm-yy")
If TodaysDate > "02-09-05" Then
MsgBox "License has expired."
Exit Sub
ElseIf TodaysDate = "24-09-05" Then
MsgBox "10 days for the license to expire."
Else
'
End If
|
|
#2
|
|||
|
|||
|
You can build your own date format by using the DatePart() function to break the date/time up into it's component parts. Also you might look at the Format() maybe there is a pre-built format that will work for you.
Something like: Code:
strDay = DatePart("d", theDate)
strMonth = DatePart("n", theDate)
strYear = DatePart("y", theDate)
newDate = strDay & "-" & strMonth & "-" & strYear
Refer to the DatePart documentation to see the different date and time components you can extract individually from a datetime value.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Date Formatting in VB Code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|