[Gambas-user] Best way converting dates into strings forth and back
Rolf-Werner Eilert
rwe-sse at osnanet.de
Fri Dec 10 10:38:56 CET 2021
Currently I think about recoding one of my projects. Here it might be
good to store dates internally as Date.
But for saving the information (and some information on top of it), I
would have to convert these dates into some kind of string, and back
into Date when loading the file(s).
So my question is, which way is the easiest and fastest to achieve this?
CStr() and CDate()?
Just to give you an idea:
Dim myDate as Date
Dim theString as String
dim parts as New String[]
myDate = Date(Now)
theString = "This is some kind of information"
theString = CStr(myDate) & Chr$(9) & theString 'is Cstr() ok?
File.Save(System.User.Home &/ "test.txt", theString)
'and later:
theString = File.Load(System.User.Home &/ "test.txt")
parts = Split(theString, Chr$(9))
myDate = CDate(parts[0]) 'is CDate() ok here?
theString = parts[1]
In the current version of my project, all dates are stored separately
(Years, Months, Days...) in Integer arrays plus string arrays for the
rest. That makes conversion into timestamps easy, but it is somewhat
roundabout to insert or delete one date.
Thanks for your advice!
Rolf
More information about the User
mailing list