I just tried these few lines of LotusScript:
Dim st_dt As String
Dim v As Variant
st_dt = Cstr(Cdat(1.5))
st_dt = Replace(st_dt, ".", "/")
v = Cdat(st_dt)
st_dt = Cstr(Cdat(1.5))
v = Cdat(st_dt)
Cdat(1.5) creates a date 12.31.1899 12:00:00 PM according to the regional settings on my machine. After conversion to a string the re-conversion to a datetime variant via Cdat only works if I replace the dots in the date part by /. It seems not to be possible to convert a string created from a Cdat date back to datetime via the same function?
I read that Cdat only knows to handle US american date format. Why does this function not interprete a date according to current regional settings?
Subject: one-way Cdat?
why not? because!it’s the way the function works.
btw: what are you trying to do???
alex
Subject: RE: one-way Cdat?
What I’m doing? A user seems to have rather strange date format on his PC. The application offers a limited range of dates to select, in a convenient format (Weekday date | date), in a string format. After selection, in QuerySave, we convert “date” back to a datetime value. This did work until today where we found a strange entry in format “M.D.YY hh:mm:ss AM/PM”. We use Cdat to convert from text format (made on the client) to the datetime format (on the same client), and that’s why I started to play around with this funtion.
Subject: RE: one-way Cdat?
The function can handle more than English/US – but M.D.YYYY is not a standard date format anywhere, so the conversion is probably choking on the 31-months-in-a-year concept. You can try to write code that handles all possible edge cases, but there’s always some joker who’s going to try a combination that nobody has ever tried before.
Subject: one-way Cdat? Wrong
cDAt is NOT limited to only works with American format but, in fact, only works with your Regional settings. For example, I use yyyy-mm-dd, and cdat works fine, yet if I use mm/dd/yyyy I will get an error.
For example for this piece of code:
Dim st_dt As String
Dim v As Variant
v = Cdat("2008-02-29")
v = Cdat("02/29/2008")
v has the right value for the first case and then I get a type mismatch on the second (“American format”) case.
You mention you are working with strings. The question I would have is HOW are you converting the date to / back to a datetime (the variant) or NotesDateTime (the type)?
It would seem if you’re giving them a string that was generated by the Regional settings it should then be able to convert that string back using the regional settings. But if you’re building the string specifically in the American format, then that’s where you will run into a problem.
Switching formats on the user will require you to parse your hard coded format into year, month day and then use a function like date or time to get the value back.
Part of the reason why I use yyyy-mm-dd is to make sure my code can handle the different date formats as many of my user use mm/dd/yyyy while others like dd/mm/yyyy. Plus I love yyyy-mm-dd because it’s self sorting! 
Subject: RE: one-way Cdat? Wrong
I completely agree with everything You’ve said.
I have only one thing to add:
Working with Dates and Times can be a pain in the neck. That’s why You ALWAYS should have fields defined as Date/Time and have validation that the entered value is a correct date/time.
If the field is a Date/Time field You can simply give the user the CalendarTime control for entering values. Then You can be pretty sure that the value is a correct date/time value. (You still have the problem that the user might manually change the value after the fact, but…)
Then it is simply a fact of using the NotesDateTime class to work with date/time alterations (adjustments).
I never use CDat().
just my thoughts about this…
Subject: RE: one-way Cdat? Wrong
How do I make date strings for user selection:
@Transform(CC_txtAvailableDates;“x”;@Do(
wd:=@Weekday(@TextToTime(x));
ds:=@If(wd=1;“So”;wd=2;“Mo”;wd=3;“Di”;wd=4;“Mi”;wd=5;“Do”;wd=6;“Fr”;“Sa”);
dt := @If(@Contains(x;" “);@Left(x;” ");x);
ds + " " + dt+“|”+dt))
makes the entries of a dialog list (on the client; field “txtDate”).
CC_txtAvailableDates is a text field that has a list of dates (typically one week) made with a conversion from NotesDateTime.LSLocalTime.
The selected value will be converted back to a datetime variant stored in field CC_datDate (which is of type DateTime):
docCurrent.CC_datDate = Cdat(docCurrent.txtDate(0))
The conversion from Date (variant or NotesDateTime) delivers a string with a date representation according to the regional settings on the client. However, the conversion back to datetime with the CDat function (on the same client) delivers an error.
Bye
Johannes
Subject: RE: one-way Cdat? Wrong
Johannes, we’d need to see your code.
You say you take a Date → String (how) it’s OK
But when you take that same string and try and go back to a Date it give you an error?
Sorry I didn’t reply sooner but Not reading this far down in the threads, I was looking for something else when I saw you replied.