Convert to SQLite Date Format.

What’s the quickest way to convert a date formatted like:


to a SQLite date format:


I know the hard way breaking the string apart and replacing the chars is there a cleaner way? Thanks!

Check out ParseDate



  dim d as date
  dim s as string="05/12/2016"
  if ParseDate(s,d) then s=d.SQLDate

Ahhh I knew there was an easy way. I was trying to use ParseDate with the format of:


and it kept giving me a boolean false.

Thank you!

you need to make some checks thought
parsedate does not handle “05-12-16” …

Thanks Jean-Yves: I was asking me why I do not used ParseDate…

All I recalled was… “Don’t use it” !

Parsedate is still usefull, but you have to check some other cases it doesnt handle
(especially if you are on a non english system …)
it is the same for number formatting …

[code]Function ToDate(extends aString as String, optional date1904 as Boolean=True) As Date

dim d,resd as date

d = new Date
if ParseDate( aString, d) then
resd = d
#pragma BreakOnExceptions false
resd = d
Catch Err As UnsupportedFormatException
resd = nil
end Try
#pragma BreakOnExceptions Default
end if

if resd<>nil then
if resd.Year<100 then
’ derniere tentative de transformation… anne mal saisie sur 2 chiffres seulement
if resd.Year>50 then resd.Year=resd.Year+1900
if resd.Year<100 then resd.Year=resd.Year+2000
end if
’ on arrive ici si on a une date excel qui est un entier
if Str(Val(aString))=aString then
if date1904 then
d.Day = d.Day+val(aString)
d.Day = d.Day+val(aString)
end if
resd = d
end if
end if

Return resd

End Function