Date-Time Formatting and Operations

Contents Hide

 

Please remember you can combine date and time formatting options to format a datetime (timestamp) value.

Date Formatting Options

Use the following elements to construct a format picture string. If you use spaces to separate the elements in the format string, these spaces will appear in the same location in the output string. The letters must be in uppercase or lowercase as shown in the table (for example, MM not mm). Characters in the format string that are enclosed in single quotation marks will appear in the same location and unchanged in the output string. Please include any adjacent spaces with this group of characters for maximum compatibility.

Value  Description

d

Day of month as digits with no leading zero for single-digit days.

dd

Day of month as digits with leading zero for single-digit days.

ddd

Day of week as a three-letter abbreviation.

dddd

Day of week as its full name.

M

Month as digits with no leading zero for single-digit months.

MM

Month as digits with leading zero for single-digit months.

MMM

Month as a three-letter abbreviation.

MMMM

Month as its full name.

y

Year as last two digits, with a leading zero for years less than 10. The same format as yy.

yy

Year as last two digits, with a leading zero for years less than 10.

yyy

Year represented by full four digits.

For example, to get the following string:

Wed, Aug 31 94

use the following string:

ddd', 'MMM dd yy

Time Formatting Options

Use the following elements to construct a format picture string. If you use spaces to separate the elements in the format string, these spaces will appear in the same location in the output string. The letters must be in uppercase or lowercase as shown (for example, ss, not SS). Characters in the format string that are enclosed in single quotation marks will appear in the same location and unchanged in the output string. Please include any adjacent spaces with this group of characters for maximum compatibility.

Value  Description

h

Hours with no leading zero for single-digit hours; 12-hour clock

hh

Hours with leading zero for single-digit hours; 12-hour clock

H

Hours with no leading zero for single-digit hours; 24-hour clock

HH

Hours with leading zero for single-digit hours; 24-hour clock

m

Minutes with no leading zero for single-digit minutes

mm

Minutes with leading zero for single-digit minutes

s

Seconds with no leading zero for single-digit seconds

ss

Seconds with leading zero for single-digit seconds

t

One character time marker string, such as A or P

tt

Multicharacter time marker string, such as AM or PM

For example, to get the following string:

maths 11:29:40 PM

use the following string:

'maths 'hh':'mm':'ss tt

DateTime Operations

DateTime values are represented in seconds. Using Expressions, you can use the addition operator (+) to increment the date or the subtract operator (-) to decrement the date.

To perform "today + 2days" you can do the following:

// Initialise the datetime control with the current time and date

datetime_picker1 = DateTime.Now()


// Go two days into the future

datetime_picker1 = datetime_picker1 + (2*86400)

// There are 86400 seconds in 24 hours

Also in expressions, when you subtract one datetime value from another the result will be an integer indicating the number of seconds between those two dates.