- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:datetime:datetime_index

Index

# ADOdb Date/Time Libaray

## Introduction

PHP native date functions use integer timestamps for computations. Because of this, dates are restricted to the years 1901-2038 on Unix and 1970-2038 on Windows due to integer overflow for dates beyond those years. This library overcomes these limitations by replacing the native function's signed integers (normally 32-bits) with PHP floating point numbers (normally 64-bits).

Dates from 100 A.D. to 3000 A.D. and later have been tested. The minimum is 100 A.D. as <100 will invoke the 2 ⇒ 4 digit year conversion. The maximum is billions of years in the future, but this is a theoretical limit as the computation of that year would take too long with the current implementation of adodb_mktime().

## Functions Replaced

- Support for Daylight Savings Time may not be completely implemented
- There may be conflicting functionality with the PHP Date Default Timezone Functionality

This library replaces native functions as follows:

    getdate()  with  adodb_getdate()
    date()     with  adodb_date()
    gmdate()   with  adodb_gmdate()
    mktime()   with  adodb_mktime()
    gmmktime() with  adodb_gmmktime()
    strftime() with  adodb_strftime()
    strftime() with  adodb_gmstrftime()

The parameters are identical, except that `adodb_date()` accepts a subset of `date()'s` field formats. Mktime() will convert from local time to GMT, and date() will convert from GMT to local time, but daylight savings is not handled currently.

This library is independant of the rest of ADOdb, and can be used as standalone code.

## Performance

For high speed, this library uses the native date functions where possible, and only switches to PHP code when the dates fall outside the 32-bit signed integer range.

## Gregorian Correction

Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian).

This is handled correctly, so:

    $t = adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)

    print $t;
    /*
     prints  24 * 3600 (1 day)
    */

## Function Descriptions

Function | Description
--- | ---
adodb_time() | Returns the current time measured in the number of seconds since the Unix Epoch
adodb_getdate() | Returns an array containing date information
adodb_date() | Convert a timestamp to a formatted local date
adodb_date2() | Same as adodb_date, but 2nd parameter accepts iso date
adodb_gmdate() | Convert a timestamp to a formatted GMT date
adodb_mktime() | Converts a local date to a unix timestamp
adodb_gmmktime() | Converts a gmt date to a unix timestamp
adodb_gmstrftime() | Convert a timestamp to a formatted GMT date
adodb_strftime() | Convert a timestamp to a formatted local date

## Notes

Useful url for generating test timestamps

Possible future optimizations include

1. Using an algorithm similar to Plauger's in “The Standard C Library” (page 428, xttotm.c _Ttotm() function). Plauger's algorithm will not work outside 32-bit signed range, so i decided not to implement it.
2. Implement daylight savings, which looks awfully complicated, see http://webexhibits.org/daylightsaving/

v5/datetime/datetime_index.txt · Last modified: 2016/01/13 07:19 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top