Skip to Content
Author's profile photo René Ullrich

Date datatype also stores the time

Hi,

we have an unexpected behavior with date variables. (PB 12.1 Classic, Build 6807)

Here a simple example:

date ld_today

ld_today = Today()

MessageBox (“Value”, string (ld_today, “dd.mm.yyyy hh:mm:ss”))

The MessageBox shows a date with time. (not 00:00:00 as expected)

If I set the value in a datawindow column of type datetime the time is also included.

This is contrary to information in the help.

Date datatype:

“The date, including the full year (1000 to 3000), the number of the month (01 to 12), and the day (01 to 31).”

Nothing about time here.

Today function:

Return values: Date

Usage: Although the datatype of the Today function is date, it can also return the current time. This occurs when Today is used as an argument for another function and that argument allows different datatypes.

But Today() is not an argument for another function here.

Workarounds I know:

Explicit conversion to date

ld_today = Date(Today())

or to datetime

MessageBox (“Value”, string (DateTime (ld_today), “dd.mm.yyyy hh:mm:ss”))

Both removes the time or sets it to 00:00:00.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Arnd Schmidt
      Arnd Schmidt

      Yep. this is the behavior since.... a couple of years.. a decade(?), Version X.X Build YYYY.

      Your code is a bit mixed.... ld_today vs. ld_test,  Date(Today) should be Date(Today())

      But yes.. nice finding.

      Plus.. this can not be changed, because then other systems using this nice feature will produce errors... 😛

      Author's profile photo René Ullrich
      René Ullrich
      Blog Post Author

      Ups. 😳

      I've corrected the code.

      Danke Arnd!