fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Assigning Date to a var???

Assigning Date to a var??? 6 months 3 weeks ago #8668

  FoxProMatt_MattSlay's Avatar Topic Author FoxProMatt_MattSlay Offline Posts: 276
In X#, how does one assign specific date to a Date Var??

For instance, in FoxPro, we say:
dDate = {2019-04-23}

or
dDate = {2019/04/23}

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 6 months 3 weeks ago #8669

  FoxProMatt_MattSlay's Avatar Topic Author FoxProMatt_MattSlay Offline Posts: 276
I think I found it in the help

www.xsharp.info/help/dateliterals.html

Date literals are formatted
 YYYY.MM.DD

Examples:
2000.01.01
2012.02.29
2015.09.25

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 6 months 3 weeks ago #8674

  robert's Avatar robert Away Posts: 1309
Matt,

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

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 6 months 3 weeks ago #8677

  FoxProMatt_MattSlay's Avatar Topic Author FoxProMatt_MattSlay Offline Posts: 276

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)
{MM-DD-YY}
{MM-DD-YYYY}
{MM/DD/YY}
{MM/DD/YYYY}

STRTICTDATE 1 or 2 (Year comes first, notice ^ symbol at the beginning.)
{^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.

Please Log in or Create an account to join the conversation.

Last edit: by FoxProMatt_MattSlay.

Assigning Date to a var??? 6 months 3 weeks ago #8679

  robert's Avatar robert Away Posts: 1309
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

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 6 months 3 weeks ago #8680

  FoxProMatt_MattSlay's Avatar Topic Author FoxProMatt_MattSlay Offline Posts: 276
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:
If Empty(dDate)
   Blah...
EndIf

I see from testing in XSI that I can define a DateTime? (nullable), but can't create Date?

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 6 months 3 weeks ago #8687

  robert's Avatar robert Away Posts: 1309
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

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 1 week 14 hours ago #11628

  Zdeněk Krejčí's Avatar Zdeněk Krejčí Offline Posts: 2
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(), ...

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 1 week 11 hours ago #11630

  robert's Avatar robert Away Posts: 1309
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

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 2 days 6 hours ago #11707

  Zdeněk Krejčí's Avatar Zdeněk Krejčí Offline Posts: 2
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

Please Log in or Create an account to join the conversation.

Assigning Date to a var??? 2 days 6 hours ago #11709

  robert's Avatar robert Away Posts: 1309
Zdenek,

That is exactly what we are doing at this moment. I only think we don't have ctot and ttoc but they will be added as part of the VFP runtime.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

  • Page:
  • 1