Skip to content

Dates & Time Zones

Verified against source (14)

  • Extensions/StringExtensions.cs
  • application/AbstractObject.cs
  • application/Functions.cs
  • Utilities/XsltFormatting.cs
  • Properties/Settings.settings
  • Configuration/Abstract.Settings.xslt
  • Configuration/SqlPattern.cs
  • Configuration/ObjectConfiguration.cs
  • Extensions/DateTimeOffsetExtensions.cs
  • decision/ImportForm.cs
  • decision/ImportForm.Fields.cs
  • Properties/Settings.settings
  • Tables/ImportForm.sql
  • Functions/TimeDimensionInterval.sql

Date columns are DATETIMEOFFSET and date properties are DateTimeOffset? (for example ImportForm.ActualCompletion). The application setting DefaultDateType is DateTimeOffset, so values whose type QBO infers from their text are treated the same way.

The one rule to remember: any date text without an offset is interpreted in the web or app server’s local time zone, using .NET’s DateTimeOffset.Parse with the server’s culture. That applies to saves, search filters, and {token} substitutions alike. By default, most QBO servers run on GMT (offset +00:00), so date text without an offset is usually stored as a GMT value.

/api/{module}/save copies request parameters onto the object through SetProperties. For a DateTimeOffset? property a string is converted like this:

Input Result
Starts with { (e.g. {today}, {now}, {firstofmonth}) Replaced with the server’s local date or time, with the server’s offset
Contains z but doesn’t end with it (e.g. 2020-10-20T20:05:05Z-420) Parsed as UTC, then shifted to an offset of the trailing minutes (-420 → -07:00)
Anything else DateTimeOffset.Parse: an explicit offset or a trailing Z is kept; otherwise the server’s local offset for that date is applied

Strings are lower-cased before parsing, and a DateTime value (from code, not the API) becomes a DateTimeOffset with the server’s offset.

When the command runs, each date parameter is formatted with DateTimeOffset.ToString() (offset included, sub-second precision dropped) and bound as DbType.DateTimeOffset. Audit columns are filled by the application: UpdatedDate with DateTimeOffset.Now, the web server’s clock. Triggers that stamp dates with SYSDATETIMEOFFSET() use the database server’s clock and zone, which need not match.

POST /api/importform/save?ID=1234&ActualCompletion=10/11/2020
  1. Save calls SetProperties(properties, true). ActualCompletion is a DateTimeOffset?, the value is a string not starting with { and with no z, so it goes to DateTimeOffset.Parse("10/11/2020").
  2. With an en-US culture that is October 11, 2020, 00:00, in the server’s local zone. On a GMT server (the default for most QBO servers): 2020-10-11 00:00:00 +00:00. On a US Eastern server (daylight time in October): -04:00. On US Pacific: -07:00.
  3. Because this is an update and ActualCompletion changed, BeforeUpdated checks whether it equals DateTime.Today (midnight today, server time). 10/11/2020 isn’t today, so it is kept. Had you sent today’s date, it would become DateTimeOffset.Now.
  4. If ActualCompletion had been omitted, ImportFormCompleteOnSave (default true) sets it to DateTimeOffset.Now.
  5. The update binds @ActualCompletion as DateTimeOffset from the string 10/11/2020 12:00:00 AM +00:00, and the ImportForm.ActualCompletion column (DATETIMEOFFSET) stores 2020-10-11 00:00:00.0000000 +00:00 (on a GMT server).
  6. The form then completes its workflow step with the same value (see Forms).

DisplayTimeZone is an application setting, empty by default. The settings screen edits it with a picker built from format:timeZoneList() (every Windows time zone ID on the server). It is read in exactly two places, both XSLT formatting functions:

  • format:formatDate(date) and format:formatDate(date, format) pass it as the target zone to formatDate(date, format, displayTimeZone).
  • format:currentTimeZone() returns it, or the server’s standard zone name when it’s empty.

It is not used when parsing input, building SQL, grouping dimensions, or serializing API responses. There is no per-user time zone.

formatDate(date, format, displayTimeZone, ignoreTimeZone) works like this:

  1. Resolves keywords (today, now, yesterday, …) with the server clock.
  2. If the text has a time part with no offset and no Z, parses it as a DateTime and formats it unchanged (no conversion).
  3. Otherwise parses a DateTimeOffset. If DateTimeOffsetUseLocalTime (default true) it converts to server local time, then, if displayTimeZone is set and differs from the server’s standard zone name, converts to that zone, then formats.

ignoreTimeZone (default from FormatDateIgnoreTimeZone, false) cuts the text at the first space or T and re-parses the date part. The resulting date-only value is midnight in the server zone, which step 3 still converts to displayTimeZone, so the setting does not stop a midnight value from moving to the previous evening in a zone west of the server.

Stored value Server zone DisplayTimeZone formatDate(…, 'd')
2020-10-11 00:00:00 -04:00 US Eastern (empty) 10/11/2020
2020-10-11 00:00:00 -04:00 US Eastern Pacific Standard Time 10/10/2020
2020-10-11 00:00:00 +00:00 GMT (default) (empty) 10/11/2020
2020-10-11 00:00:00 +00:00 GMT (default) Eastern Standard Time 10/10/2020
2020-10-11 00:00:00 +00:00 US Eastern (empty) 10/10/2020 (converted to server local)

Pass a third argument to override the zone for one template: format:formatDate(@ActualCompletion, 'd', 'Eastern Standard Time').

Search parameters on date columns are written into the WHERE clause as quoted literals, after Functions.DateTimeReplace(DbType.DateTimeOffset, value). For text that isn’t a {token}, that function runs DateTimeOffset.TryParse and returns ToString(), which adds the server’s offset to date text that had none:

GET /api/importform/search?ActualCompletion=-10/11/2020,10/12/2020
-- on a GMT server
[ImportForm].[ActualCompletion] BETWEEN '10/11/2020 12:00:00 AM +00:00' AND '10/12/2020 12:00:00 AM +00:00'

The operators are ! (not equal), > (>=), < (<=), and -a,b (BETWEEN, inclusive at both ends). So a day filter covers the server’s local calendar day. Comparisons are by instant: a value saved as 2020-10-11 21:30:00 -07:00 (4:30 AM October 12 GMT) falls on October 12 for this filter. To filter on another zone’s day, send the offset: ActualCompletion=-2020-10-11T00:00:00-07:00,2020-10-11T23:59:59-07:00.

Dashboards that group a date column (Dimension=ActualCompletion) join to dbo.TimeDimensionInterval(@ActualCompletionStart, @ActualCompletionEnd, @ActualCompletionIntervals) on ActualCompletion >= BeginDate AND ActualCompletion < EndDate. The function takes DATETIMEOFFSET arguments but returns BeginDate and EndDate as DATETIME, which drops the offset and keeps the server’s wall-clock time. SQL Server compares a DATETIME with a DATETIMEOFFSET as +00:00, so the buckets are the server’s calendar days treated as UTC days.

On a GMT server, the default for most QBO servers, that matches the filters. On a US Eastern server, the 2020-10-11 bucket covers 8:00 PM October 10 to 8:00 PM October 11 Eastern: a value at midnight Eastern stays in its day, but a value at 9:00 PM Eastern on October 11 lands in the 2020-10-12 bucket while a day filter for October 11 includes it.

  • {today}, {yesterday}, {firstofmonth}, and the other tokens start from DateTime.Today on the server.
  • format:today() and the today/now keywords in formatDate use the server clock.
  • Business-day arithmetic (AddBusinessDays) converts to server local time unless a time zone ID is passed, and returns a value with the server’s offset.
  • Send ISO 8601 with an offset (2020-10-11T14:30:00-04:00) for every date. QBO keeps what you send regardless of the server zone or culture.
  • For date-only business values, send midnight in the business’s zone with its offset. Avoid Z unless the business day is a UTC day.
  • Leave DisplayTimeZone empty unless the server zone isn’t the zone readers expect, and test date-only fields in that case. On a GMT server, any US display zone shows midnight values as the previous day.
  • In custom SQL, group with CAST(col AT TIME ZONE '<zone>' AS date) to report every row in one zone; CAST(col AS date) keeps the zone each value was recorded in.
  • Don’t send a date-only value equal to today when you mean midnight on an ImportForm update; it becomes the current time.