OpenNTF.org - Date Manipulation due to diffe
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Date Manipulation due to different date formats across different countries. 
Rating:
Not Rated Yet 
Contributor:
Peter Abatan 
Category:
Lotusscript 
Type:
Date/Time functions 
Notes Version:
R6.x 
Last Modified:
06 Jul 2006 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
|--------------First Function--------------|


Function ConvertDate(TwoDay As String) As String
If Len(TwoDay) = 9 Or Len(TwoDay) = 8 Then
bigStr$ = TwoDay
littleStr$ = "/"
positionOfChar& = Instr(1, bigStr$, littleStr$)

'Get the day of the month part of the date
If positionOfChar& = 2 Then 'Single digit day of the month
subString = "0" + Left$(bigStr$, 1)
Elseif positionOfChar& = 3 Then 'Double digit day of the month
subString = Left$(bigStr$, 2)
End If

'Get the month part of the date
If positionOfChar& = 2 Then 'Single digit day of the month
subStringx = Mid$(bigStr$, 3, 2)
If Isnumeric(subStringx) Then 'Month is a double digit number
ConvertDate = subString + "/" + subStringx + "/" + Right$(bigStr$, 4)
Else 'Month is not a double digit number
ConvertDate = subString + "/" + "0" + Mid$(bigStr$, 3, 1) + "/" + Right$(bigStr$, 4)
End If
Elseif positionOfChar& = 3 Then 'Double digit day of the month
subStringx = Mid$(bigStr$, 4, 2)
If Isnumeric(subStringx) Then 'Month is a double digit number
ConvertDate = subString + "/" + subStringx + "/" + Right$(bigStr$, 4)
Else 'Month is not a double digit number
ConvertDate = subString + "/" + "0" + Mid$(bigStr$, 4, 1) + "/" + Right$(bigStr$, 4)
End If
End If
Else
ConvertDate = TwoDay
End If
End Function



|--------------Second Function--------------|

Function ConvertDateUS( ) As String
bigStr$ = Cstr(Today())
littleStr$ = "/"
positionOfChar& = Instr(1, bigStr$, littleStr$)

'Get the month part of the date
If positionOfChar& = 2 Then 'Single digit month
subString = "0" + Left$(bigStr$, 1)
Elseif positionOfChar& = 3 Then 'Double digit month
subString = Left$(bigStr$, 2)
End If

'Get the day of the month part of the date
If positionOfChar& = 2 Then 'Single digit month
subStringx = Mid$(bigStr$, 3, 2)
If Isnumeric(subStringx) Then 'Day of the month is a double digit number
ConvertDateUS = subStringx + "/" + subString + "/" + Right$(bigStr$, 4)
Else 'Day of the month is not a double digit number
ConvertDateUS = "0" + Mid$(bigStr$, 3, 1) + "/" + subString + "/" + Right$(bigStr$, 4)
End If
Elseif positionOfChar& = 3 Then 'Double digit month
subStringx = Mid$(bigStr$, 4, 2)
If Isnumeric(subStringx) Then 'Day of the month is a double digit number
ConvertDateUS = subStringx + "/" + subString + "/" + Right$(bigStr$, 4)
Else 'Day of the month is not a double digit number
ConvertDateUS = "0" + Mid$(bigStr$, 4, 1) + "/" + subString + "/" + Right$(bigStr$, 4)
End If
End If
End Function

Usage / Example
The first function called ConvertDate helps you to standardize different DMY date formats to dd/mm/yyyy. So if the date format on your computer is d/m/yyyy or dd/m/yyyy or d/mm/yyyy, it will standardise it to dd/mm/yyyy making it easy to compare date afterwards.

The second function called ConvertDateUS takes the US date format and changes it to the dd/mm/yyyy format. So if the date is m/d/yyyy or mm/d/yyyy or m/dd/yyyy, it will standardise it to dd/mm/yyyy making it easy to compare date afterwards.
 Comments

No documents found

 Add your comment!