How to get the current date

I need the current date & it is not easy to find how in elements documentation nor in Talk. Hope someone knows off top of head & can tell me. I need it in mm/dd/yy format, but I can’t easily find how to get it in any format.

What platform? On any of them, if you use our cross-platform Elements RTL library you can use DateTime.UtcNow.

I’m using Browser based Water Island. All work done in browser & s/b compatible with the modern browsers, Chrome, FireFox, Edge, Safari, Apple OS.

So this works?

method GetDate(): String;
begin
var sDateTime := DateTime.UtcNow;
var sDate := sDateTime.Month + ‘/’ + sDateTime.Day + ‘/’ + sDateTime.Year;
RESULT := sDate;
end;

1 Like

Yes. You can also use ToString() on the datetime, with a format string, instead of manually putting therapierest together.

.ToString(“dd/mm/yyyy”)

Or the like.

1 Like

The current date eludes me no matter what I do.
The only soln I’ve found is letting JavaScript do it. I’d prefer WASM.elements.

var sDate1, sDate2 : String;
var MyDate : DateTime := DateTime.UtcNow;
sDate1 := MyDate.ToString(“dd/mm/yyyy”);
Console.write('sDate1= ’ + sDate1): Outputs sDate1= (i.e. empty string)

sDate2 := MyDate.Month.ToString + ‘/’ + MyDate.Day.ToString + ‘/’ + MyDate.Year.ToString;
Console.write('sDate2= ’ + sDate2); Outputs sDate2 = sDate2= 1/-256/-29226 (i.e. WTF???)

Moreover how to get the local time of the User? Uct = London’s date!
var MyDate : DateTime := DateTime.Now; Did not work.