xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

{ˆ }

Literal DateTime value.

Syntax

{ˆ [<YYYY/MM/DD>] [<hh:mm:ss[.ccc>]] [AM|PM] }

Arguments

<YYYY/MM/DD>
The Date part of a DateTime value must be coded with digits in the sequence Year/Month/Day where the slash must be used as delimiting character.
<hh:mm:ss.ccc>
The Time part must be coded in the sequence Hour:Minute:Second where the colon is used as delimiter. Optionally, the seconds value can be followed by a period and up to three digits (.ccc) indicating fractions of a second in milliseconds. The Time part follows the Date part and must be separated with a blank space.
AM|PM
When the Time part is coded using a 12 hour clock, the suffix AM or PM can be added. The suffix must be separated from the Time part with a blank space.

Description

The DateTime operator begins with an open curly brace, followed by a caret and ends with a closing curly brace. It combines a Date value with a Time. DateTime values can be coded as literal values, consisting either of the Date part, the Time part, or both of them. However, if the Time part is omitted, it defaults to 00:00h. When the Date part is omitted, the date defaults to December 30th, 1899 (which is the start date for COM/OLE defined by Microsoft). The AM or PM suffix allows for coding a literal DateTime value using a 12 or 24 hour clock.

In contrast to regular Date value, DateTime values are independent of the SET DATE or SET EPOCH settings. A literal DateTime value must always be coded in the same way and does not follow country specific date formats.

DateTime values can be stored in a database when the corresponding database field is created with "T" as field type. The length of a "T" field is the same as for a regular Date field: 8 bytes.

Besides these differences, DateTime values can be used in the same way as regular Date values. When a value of Valtype()=="D" must be passed as parameter, it can be either a Date or a DateTime value.

Info

See also:CtoD(), CtoT(), DateTime(), HB_IsDateTime(), TtoC(), TtoS()
Category: Operators , Special operators , xHarbour extensions
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example outlines basic operations with DateTime values and
// lists their results.

   PROCEDURE Main
      LOCAL d1, d2, nDiff

      SET CENTURY ON
      SET TIME FORMAT TO "hh:mm:ss.ccc"

      ? DateTime()                      // result: [today] [systemtime]
      ? {ˆ 2007/04/26}                  // result: 04/26/2007
      ? {ˆ 05:30:12.345}                // result: 12/30/1999 05:30:12.345
      ? {ˆ 05:30:12.345 PM}             // result: 12/30/1999 17:30:12.345

      ** Empty value
      ? d1 := {ˆ 0/0/0 }                // result:   /  /
      ? Empty( d )                      // result: .T.

      ** difference between DateTime and Date
      ? d1 := {ˆ 2007/04/26 18:30:00 }  // result: 04/26/2007 18:30:00.000
      ? d2 := StoD("20070426")          // result: 04/26/2007
      ? nDiff := d1-d2, "days"          // result: 0.77 days
      ? TString( nDiff*86400 )          // result: 18:30:00

      ** Adding 2 days to DateTime
      ? d1 + 2                          // result: 04/28/2007 18:30:00.000

      ** Adding 2 hours to DateTime
      ? d1 + 2/24                       // result: 04/26/2007 20:30:00.000

      ** Adding 2 minutes to DateTime
      ? d1 + 2/(24*60)                  // result: 04/26/2007 18:32:00.000

      ** Adding 2 seconds to DateTime
      ? d1 + 2/(24*3600)                // result: 04/26/2007 18:30:02.000

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe