-1

How can i display the current date and time in a field with date type. I can show the current date with today() but how can i display the current time. Furthermore i want display these two in one field.

Thanks for every help. Felix

DAXaholic
  • 33,312
  • 6
  • 76
  • 74

2 Answers2

7

I am afraid that is not possible as a field of type date holds just that - the date. Use type utcdatetime and the appropriate control UtcDateTimeEdit to show dates & times in one control.

To retrieve the current date & time you can call DateTimeUtil::utcNow() to which you may want to apply the local time zone via DateTimeUtil::applyTimeZoneOffset

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
0

Try this:

utcDateTime _utcDateTime;
;
_utcDateTime = DateTimeUtil::getSystemDateTime();

Then you can extract separately the date and the time if you want.

Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
  • 1
    Thanks for this idea, but i want show the date and the time in a field with date type. Thus the types are incompatible. I think I have to change the field again if I want to display both... – Felix Schneider Aug 11 '16 at 07:08
  • Try this to extract the date by date field, and time in str utcDateTime _utcDateTime; date _date; TimeOfDay _hour; int _min, _sec; str _Hourstr; ; _utcDateTime = DateTimeUtil::getSystemDateTime(); _Date = DateTimeUtil::date(_utcDateTime); //Date _hour = DateTimeUtil::time(_utcDateTime); _hour = _hour /60; _hour = _hour /60; _min = DateTimeUtil::minute(_utcDateTime); _sec = DateTimeUtil::second(_utcDateTime); _Hourstr = int2str(_hour) + ":" + int2str(_min) + ":" + int2str(_Sec); //Hour – Jonathan Bravetti Aug 11 '16 at 12:04