datePart: Extract element from a vague date

Description

The NBN Gateway stores dates in three fields: startDate, endDate and dateType. This allows for storage of date with various degrees of uncertainty (referred to as "vague dates"). This function allows the year, month, week or day to be extracted from the vague date whilst properly taking into account the dateType.

Usage

1
2
datePart(startDate, endDate, dateType, part = c("year", "month", "week",
  "day"))

Arguments

startDate

Date returned by NBN Gateway as a string in the format yyyy-mm-dd

endDate

Date returned by NBN Gateway as a string in the format yyyy-mm-dd

dateType

One or two letter code, returned by NBN Gateway, describing the nature of the vague date (see details)

part

The type of information you want to extract. Possibilities are year (default), month, week or day

Details

The start and end dates are returned by the NBN Gateway as strings in the format yyyy-mm-dd. The dateType is a one or two letter code as follows:

The value that is returned depends both on the element that is requested and the dateType of the vague date that is passed to the function as follows:

Value

An integer number. -1 is returned if the requested element is not available or does not make sense for the given dateType (see details)

Author(s)

Stuart Ball, JNCC stuart.ball@jncc.gov.uk

Examples

1
2
datePart("2010-06-15", "2010-06-15", "D", "year") # returns 2010
datePart("2010-06-15", "2010-06-15", "D", "mon") # returns 6

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.