Page 1 of 2
Assigning Date to a var???
Posted: Tue Apr 23, 2019 3:38 pm
by Anonymous
In X#, how does one assign specific date to a Date Var??
For instance, in FoxPro, we say:
or
Assigning Date to a var???
Posted: Tue Apr 23, 2019 4:06 pm
by FoxProMatt
I think I found it in the help
https://www.xsharp.eu/help/dateliterals.html
Date literals are formatted
Examples:
Assigning Date to a var???
Posted: Tue Apr 23, 2019 6:02 pm
by robert
Matt,
I am planning to add that syntax as allowed syntax for Date Literals to the FoxPro dialect
Robert
Assigning Date to a var???
Posted: Tue Apr 23, 2019 6:50 pm
by FoxProMatt
I am planning to add that syntax as allowed syntax for Date Literals to the FoxPro dialect.
That would be perfect, because it will eliminate one of the code transformations to get from VFP to X#.
BTW - There is one important setting that affects Dates, and it's called SET STRICTDATE [0 | 1 | 2]. This can also factor in another setting if a 2-digit year is used, in which another command SET CENTURY ON | OFF | TO [nCentury [ROLLOVER nYEAR]] comes into play to deal with the CENTURY part of the year (again, only if 2-digit YY was used).
For all dates, the separator can be a dash or a slash.
STRICTDATE 0 (Year comes at the end)
Code: Select all
{MM-DD-YY}
{MM-DD-YYYY}
{MM/DD/YY}
{MM/DD/YYYY}
STRTICTDATE 1 or 2 (Year comes first, notice ^ symbol at the beginning.)
Code: Select all
{^YY-MM-DD}
{^YYYY-MM-DD}
{^YY/MM/DD}
{^YYYY/MM/DD}
For both of the above if year is a 2-digit number, it will imply the century from the YY and store it as YYYY in whatever assignment was made.
Assigning Date to a var???
Posted: Tue Apr 23, 2019 9:08 pm
by robert
Matt,
It will be difficult to emulate this STRICTDATE feature and have real constants at the same time. When I understand you correctly then STRICTDATE is a runtime setting. That would mean that the same code would behave differently when called with a different settings. Then it is no longer a date literal imo, but we would have to store the date literals in another form (a string for example) and then convert it to a date on the fly using the current setting.
Dash or Slash is not a problem. SetCentury is also not a problem ( we support that for the runtime already). The date literal gets translated to a constructor call for the date type. Inside the constructor we are handling dates of 2 digits and we are supporting SetCentury (and SetEpoch, which is probably the same as your ROLLOVER clause).
Robert
Assigning Date to a var???
Posted: Tue Apr 23, 2019 9:17 pm
by FoxProMatt
Another headache will be that VFP allows for EMPTY Date types, so it could be {} or {//} and that is "Empty", but a TYPE of Date.
Code may say:
I see from testing in XSI that I can define a DateTime? (nullable), but can't create Date?
Assigning Date to a var???
Posted: Wed Apr 24, 2019 6:33 am
by robert
Matt,
Defining an empty date with {//} or {- -} should be possible I think, defining an empty with with {} will be difficult, since that is used for an empty array already.
And of course you can create a date. But the date literal and date keywords are not supported in Core dialect and xsi runs in core at this moment. This works (if you have the references to XSharp.Core and XSharp.RT):
var dDate:= Xsharp.__Date{2019,4,24}
Not elegant, but will be replaced with
var dDate := 2019.04.24
once we allow you to set the dialect on xsi.exe
You are free to discover xsi.exe at this moment, as long as you remember that it runs in Core so has no built in support for Xbase style variables like Date, Array etc.
Robert
Assigning Date to a var???
Posted: Thu Nov 07, 2019 3:04 am
by Zdeněk Krejčí
It dependense on set date
We use
Set date german
Date is in format {dd.mm.rrrr}
Also for datetime and date functions like Ctod("03.10.2019").
Dtoc(), transform(), ...
Assigning Date to a var???
Posted: Thu Nov 07, 2019 5:55 am
by robert
Zdenek,
SET DATE is a runtime setting.
Date literals are handled at compile time.
It will be difficult to apply the runtime logic at compile time, unless we convert the {dd.mm.rrrr} to a string and then do the conversion at runtime.
Robert
Assigning Date to a var???
Posted: Tue Nov 12, 2019 10:30 am
by Zdeněk Krejčí
Robert,
I think good kompromise would be to use strict date format in date literals e.g. {^2019-11-12} for compile-time and full support in conversion function like dtoc(), ctod(), transform(), ctot(), ttoc() for run-time.
Zdeněk