DateTime to Short date


I have to convert a DateTime to a short date like “3/18/20” but the code:

txtAdd30.Text = ldDemoDate.ToString(nil, DateTime.FormatStyles.Short)

Adds the time. How do I get just the date Like the older version Date.ShortDate?

Think I got it:

txtAdd30.Text = ldDemoDate.ToString(nil, DateTime.FormatStyles.Short, DateTime.FormatStyles.None)

Note that trying to format it this way means you get whatever the current users system settings are

IF you are trying tp put this in a db you should put it in in a format YOU absolutely dictate every aspect of and only use the format styles for display to the user

That said SHORT is documented as giving just the date but I suspect if you check you system settings it may be set to do something else
On macOS this should be under System Preferences > Language & Region > Advanced > Date

EDIT : oh yeah you get the default time style without that last param :slight_smile:

This date is for HigherLogic and that is the required format.

Region has no effect.

Norman is this you full time job now? Answering questions on the forum. :slight_smile:

never was
just trying to be helpful
I’m actually waiting on compiles most of the time I answer stuff
yes - Xojo takes that long to start a debug run of the project I’m working on - usually somewhere between 3 and 5 minutes :frowning:

If my Mac has that setting configured as DD-MM-YYYY with your code the label will show 18-03-2020
If you always want to show 3/18/20 then is better that you define a Locale, something like:

Var USLocale As New Locale("en-US") txtAdd30.Text = ldDemoDate.ToString(USLocale, DateTime.FormatStyles.Short, DateTime.FormatStyles.None)