Convert to API 2 "SelectedDateLabel.Value = "Selected Date: " + ThDte.LongDate"

How do I convert this line of code to API 2.
SelectedDateLabel.Value = "Selected Date: " + ThDte.LongDate
It seems from examples in this forum it is something like
SelectedDateLabel.Value = "Selected Date: " + ThDte.Tostring( DateTime.FormatStyles.full)
but that seems too long. Suggestions?

BTW this basically came from the calendar window example.

That is correct. API 2 is quite verbose.

Well. It is consistent and easy to understand.

if you need this syntax frequently you could use extends then it looks same
or a method
= ThDte.LongDate
= LongDate(ThDte)

Function LongDate( extends dt as DateTime ) as string
   Return dt.Tostring( locale.Current , DateTime.FormatStyles.full, DateTime.FormatStyles.full )
end function

EDIT - fixed

Sorry Tim.
That long construction isn’t right, and I’ve tried a few varieties also.

What does pass the analyzer is
ThDte.ToString
Anything in the parentheses gets denied.

Even Norm’s inside the parentheses doesn’t work

No it wouldnt but you do need to do some experimentation on your own as well
Otherwise all you end up with is cut & paste from the forums and you never learn how to do this stuff for yourself

I know. I’m trying to be patient.

Then you’ll need to pass in the locale also. I didn’t remember whether optional parameters before the param you pass were accepted. Sounds like not. The signature for ToString is

DateTime.ToString(loc As Locale = Nil, dateStyle As DateTime.FormatStyles = 
DateTime.FormatStyles.Medium, timeStyle As DateTime.FormatStyles = 
FormatStyles.Medium) As String

There are 3 parameters, all of them optional. If you want to use the 2nd only, you also have to pass the first, if I recall correctly.

I don’t have API 2 to test on, but try

SelectedDateLabel.Value = "Selected Date: " + ThDte.Tostring(Locale.Current, DateTime.FormatStyles.full)

Argh. I was looking on the wrong page. I didn’t look on ToString. I was looking on Formatstyles.

It also implies Locale isn’t needed, but without it, it didn’t work.

Edit: I posted my response as Tim did.
My code: ThDte.ToString(Locale.Current, DateTime.FormatStyles.full)

or the extends I corrected above :stuck_out_tongue:

1 Like

Yup. I need to learn extends

The last element should be DateTime.FormatStyles.None no?

I would say that depends on what long date returned if you’re trying to make an equivalent

I guess Arthur is referring to Date.LongDate and that is just Full Date and no Time.

Actually I was trying to understand some API 2 code and it didn’t matter what was used.