Static methods providing conversions.

package dstruct_common

 Methods

Converts a MySQL Timestamp to a Unix Timestamp

MySQLDateTimeToUTS(string $stamp) : integer
Static

For compatability with Windows languages, a timestamp of 1900-01-01 00:00:00 returns 0 which is 1970-01-01 01:00:00
The function uses PHP's strtotime(), which returns false for timestamps before the start of the Unix Epoch in 1970 on Windows. If a timestamp is before 1970, the function will return 0 as above.
To ensure consistency in the database, this function should be used in conjunction with UTSToMySQLDate().

Parameters

$stamp

string

Format of 'yyyy-mm-dd hh:mm:ss'

Returns

integer

Converts a MySQL date to a Unix Timestamp

MySQLDateToUTS(string $date) : integer
Static

For compatability with Windows languages, a date of 1900-01-01 returns 0 which is 1970-01-01 01:00:00
The function uses PHP's strtotime(), which returns false for dates before the start of the Unix Epoch in 1970 on Windows. If a date is before 1970, the function will return 0 as above.
To ensure consistency in the database, this function should be used in conjunction with UTSToMySQLTimestamp().

Parameters

$date

string

Format of 'yyyy-mm-dd'

Returns

integer

Gets the date part of a UTS If a UTS needs to be compared (for instance finding in an array), it may be desirable to attempt to match days e.g.

UTSDatePart(integer $uts) : integer
Static

25/08/2008 to 25/08/2008. If one or more of the UTS vars is a timestamp, this won't work if they are not converted to a 'day' timestamp

Parameters

$uts

integer

UTS timestamp

Returns

integerUTS timestamp

Converts a Unix Timestamp to a MySQL date

UTSToMySQLDate(integer $uts, boolean $olddate) : string
Static

If $uts = false, returns '1900-01-01' or 1970-01-01. This is to maintain compatability with databases which have to be usable with Windows programming languages which error when confronted with 0000-00-00 dates.

Parameters

$uts

integer

$olddate

boolean

Return 1900 rather than 1970 if true.

Returns

stringFormat 'yyyy-mm-dd hh:mm:ss'

Converts a Unix Timestamp to a MySQL DateTime

UTSToMySQLDateTime(integer $uts, boolean $olddate) : string
Static

For MySQL Timestamp fields, you can just insert the UTS without conversion.

Parameters

$uts

integer

UTC Timestamp

$olddate

boolean

Return 1900 rather than 1970 dates when $uts evaluates to false

Returns

stringFormat 'yyyy-mm-dd hh:mm:ss'

Get just the date part of a UTS in MySQL format

UTSToMySQLTime(integer $uts) : string
Static

Parameters

$uts

integer

Returns

stringTime in format 'nn:nn:nn'

Converts a 'natural' date to MySQL format

UserDateToMySQL(string $userdate) : string
Static

Parameters

$userdate

string

in format 'dd/mm/yyyy'

Returns

stringin format 'yyyy-mm-dd'

Converts a 'natural' date into a Unix Timestamp

UserDateToUTS(string $date) : integer
Static

The date must be valid.

Parameters

$date

string

Format 'dd/mm/yyyy'

Returns

integer

Converts a 'natural' timestamp into a Unix Timestamp

UserTimestampToUTS(string $timestamp) : integer
Static

The timestamp must be valid.

Parameters

$timestamp

string

Format 'dd/mm/yyyy hh:mm:ss'

Returns

integer

Converts a string of six numeric characters into a UK Sort Code

numericToSortCode(string $numeric) : string
Static

Remember to store your numeric characters as a string rather than integer so that leading zeros are preserved

see \Convert::sortCodeToNumeric()

Parameters

$numeric

string

expects format nnnnnn

Returns

stringin format nn-nn-nn

Converts a formatted UK Sort Code to a numeric string

sortCodeToNumeric(string $code) : string
Static
see \Convert::numericToSortCode()

Parameters

$code

string

in format nn-nn-nn

Exceptions

\DStructGeneralException

Returns

stringin format nnnnnn

Class constructor

__construct()