Assigning Date to a var???

This forum is meant for questions and discussions about the X# language and tools
Anonymous

Assigning Date to a var???

Post by Anonymous »

In X#, how does one assign specific date to a Date Var??

For instance, in FoxPro, we say:

Code: Select all

dDate = {2019-04-23}
or

Code: Select all

dDate = {2019/04/23}
FoxProMatt

Assigning Date to a var???

Post by FoxProMatt »

I think I found it in the help

https://www.xsharp.eu/help/dateliterals.html

Date literals are formatted

Code: Select all

 YYYY.MM.DD
Examples:

Code: Select all

2000.01.01
2012.02.29
2015.09.25
User avatar
robert
Posts: 4243
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assigning Date to a var???

Post by robert »

Matt,

I am planning to add that syntax as allowed syntax for Date Literals to the FoxPro dialect

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

Assigning Date to a var???

Post 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.
User avatar
robert
Posts: 4243
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assigning Date to a var???

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

Assigning Date to a var???

Post 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:

Code: Select all

If Empty(dDate)
   Blah...
EndIf
I see from testing in XSI that I can define a DateTime? (nullable), but can't create Date?
User avatar
robert
Posts: 4243
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assigning Date to a var???

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Zdeněk Krejčí
Posts: 19
Joined: Wed Sep 04, 2019 8:07 am

Assigning Date to a var???

Post 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(), ...
User avatar
robert
Posts: 4243
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assigning Date to a var???

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Zdeněk Krejčí
Posts: 19
Joined: Wed Sep 04, 2019 8:07 am

Assigning Date to a var???

Post 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
Post Reply