DATESERIAL

DATESERIAL(the_date, date_format)
Returns the date serial number given a date in text format.

the_dateThe birthday of the person.
date_formatThe date format "UK" or "US".

REMARKS
* If "dateFormat" is left blank, then "UK" is used.
* If "birthday" is after todays date, then
Columns=1

 A
1=JS.DATESERIAL("1/11/1977")
2=JS.DATESERIAL("11/1/1977")
3=JS.DATESERIAL("1/01/2000")
4=JS.DATESERIAL("01/1/2000")
5=JS.DATESERIAL("1 Jan 2000")
6=JS.DATESERIAL("01 January 2000")
7=JS.DATESERIAL("01/13/2000")
8=JS.DATESERIAL("01/13/2000","US")
9=JS.DATESERIAL("01 Seb 2000") invalid date

Public Function DATESERIAL(ByVal sTheDate As String, _ 
         ByVal sDateFormat As String) _
         As Variant

Dim arcomponents As Variant
Dim iyear As Integer
Dim imonth As Integer
Dim iday As Integer

   If (InStr(sTheDate, "/") > 0) Then
      arcomponents = Split(sTheDate, "/")
      If (Len(arcomponents(0)) = 1) Then arcomponents(0) = "0" & arcomponents(0)
      If (Len(arcomponents(1)) = 1) Then arcomponents(1) = "0" & arcomponents(1)
      sTheDate = arcomponents(0) & "/" & arcomponents(1) & "/" & arcomponents(2)
      
      Select Case sDateFormat
         Case "dd/mm/yyyy":
            iyear = Mid(sTheDate, 7, 4)
            imonth = Mid(sTheDate, 4, 2)
            iday = Left(sTheDate, 2)
      
         Case "mm/dd/yyyy":
            iyear = Mid(sTheDate, 7, 4)
            imonth = Left(sTheDate, 2)
            iday = Mid(sTheDate, 4, 2)
            
         Case Default:
            DATESERIAL = "format not found"
            Exit Function
            
      End Select
   End If
                 
   DATESERIAL = VBA.DateSerial(iyear, imonth, iday)
End Function

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext