netDateTime

Overview

netDateTime is a Dyalog namespace of methods that deals with Dates and Time using Microsoft .Net.

Methods using ⎕TS

⎕TS is an APL system constant returning the time as a seven vector element in that order: Year, Month, Day, Hour, Minute, Second, Millisecond.

      dt ←     TsToDateObject ⎕TS    ⍝ returns a .Net DateTime Object
               TsToDateString ⎕TS    ⍝ returns a character representation of the date
               TsToTimeString ⎕TS    ⍝ returns a character representation of the time
               TsToDayOfWeek  ⎕TS    ⍝ returns the day of week as a number (Sunday = 1)
      oaDate ← TsToOADate     ⎕TS    ⍝ returns the OA Date as a number

Methods using OADates

OA dates is a Microsoft standard used in Office applications.

      dt ← OADateToDateObj    oaDate     ⍝ returns a .Net DateTime Object
           OADateToTs         oaDate     ⍝ returns the equivalent ⎕TS from the supplied OADate
           OADateToDateString oaDate     ⍝ returns a character representation of the date
           OADateToTimeString oaDate     ⍝ returns a character representation of the time

Methods using .Net DateTime object

          DayOfWeek  dt     ⍝ returns the day of week as a number (Sunday = 1)
      'd' FormatDate dt     ⍝ returns a character representation of the DateTime object

Niladic methods

      NowToDateString       ⍝ returns a character representation of the current date
      NowToTimeString       ⍝ returns a character representation of the current time

Altering the character representation of the Date or Time

The character representation of the Date and Time can be altered using a similar scheme used in Excel formatting. The corresponding method just need to be resaved with the desired formatting string to obtain the desired result. Here is some possibility that can be used for formatting:

Format specifier

Description

d

The day of the month, from 1 through 31

dd

The day of the month, from 01 through 31

ddd

The abbreviated name of the day of the week

dddd

The full name of the day of the week

h

The hour, using a 12-hour clock from 1 to 12

hh

The hour, using a 12-hour clock from 01 to 12

H

The hour, using a 24-hour clock from 0 to 23

HH

The hour, using a 24-hour clock from 00 to 23

m

The minute, from 0 through 59

mm

The minute, from 00 through 59

M

The month, from 1 through 12

MM

The month, from 01 through 12

MMM

The abbreviated name of the month

MMMM

The full name of the month

s

The second, from 0 through 59

ss

The second, from 00 through 59

t

The first character of the AM/PM designator

tt

The AM/PM designator

y

The year, from 0 to 99

yy

The year, from 00 to 99

yyy

The year, with a minimum of three digits

yyyy

The year as a four-digit number

yyyyy

The year as a five-digit number

The following single letter can be used also:

Format specifier

Description

Pattern value

t

ShortTimePattern

h:mm tt

d

ShortDatePattern

M/d/yyyy

T

LongTimePattern

h:mm:ss tt

D

LongDatePattern

dddd, MMMM dd, yyyy

f

(combination of D and t)

dddd, MMMM dd, yyyy h:mm tt

F

FullDateTimePattern

dddd, MMMM dd, yyyy h:mm:ss tt

g

(combination of d and t)

M/d/yyyy h:mm tt

G

(combination of d and T)

M/d/yyyy h:mm:ss tt

How to install netDateTime in your workspace

  1. Download netDateTime.v1.0.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ⍟ netDateTime

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Optionally to de-script the namespace you can do:

#.netDateTime←{('n' ⎕NS ⍵)⊢n←⎕NS ''}#.netDateTime

Version Information

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


See also: Studio/EncodeDecodeDates


CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogDotNetUtilities - CategoryDotNet

netDateTime (last edited 2015-07-31 00:45:44 by PierreGilbert)