You are here

function date_sql_pad in Date 8

Same name and namespace in other branches
  1. 5 date.inc \date_sql_pad()
  2. 6.2 date_api_sql.inc \date_sql_pad()
  3. 6 date_api_sql.inc \date_sql_pad()
  4. 7.3 date_api/date_api_sql.inc \date_sql_pad()
  5. 7 date_api/date_api_sql.inc \date_sql_pad()
  6. 7.2 date_api/date_api_sql.inc \date_sql_pad()

A helper function to do cross-database padding of date parts.

Parameters

string $str: A string to apply padding to

int $size: The size the final string should be

string $pad: The value to pad the string with

string $side: The side of the string to pad

File

date_api/date_api.module, line 723
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_sql_pad($str, $size = 2, $pad = '0', $side = 'l') {
  switch ($side) {
    case 'r':
      return "RPAD({$str}, {$size}, '{$pad}')";
    default:
      return "LPAD({$str}, {$size}, '{$pad}')";
  }
}