|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Appel\SqliteFunctions\Functions; |
| 4 | + |
| 5 | +class DateFormat extends AbstractFunction |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @return \Closure |
| 9 | + * @throws \Exception |
| 10 | + */ |
| 11 | + public function mysql() |
| 12 | + { |
| 13 | + return function ($date, $format) { |
| 14 | + |
| 15 | +// function format() |
| 16 | +// { |
| 17 | + // MySQL |
| 18 | +// %a Abbreviated weekday name (Sun to Sat) |
| 19 | +//%b Abbreviated month name (Jan to Dec) |
| 20 | +//%c Numeric month name (0 to 12) |
| 21 | +//%D Day of the month as a numeric value, followed by suffix (1st, 2nd, 3rd, ...) |
| 22 | +//%d Day of the month as a numeric value (01 to 31) |
| 23 | +//%e Day of the month as a numeric value (0 to 31) |
| 24 | +//%f Microseconds (000000 to 999999) |
| 25 | +//%H Hour (00 to 23) |
| 26 | +//%h Hour (00 to 12) |
| 27 | +//%I Hour (00 to 12) |
| 28 | +//%i Minutes (00 to 59) |
| 29 | +//%j Day of the year (001 to 366) |
| 30 | +//%k Hour (0 to 23) |
| 31 | +//%l Hour (1 to 12) |
| 32 | +//%M Month name in full (January to December) |
| 33 | +//%m Month name as a numeric value (00 to 12) |
| 34 | +//%p AM or PM |
| 35 | +// %r Time in 12 hour AM or PM format (hh:mm:ss AM/PM) |
| 36 | +//%S Seconds (00 to 59) |
| 37 | +//%s Seconds (00 to 59) |
| 38 | +//%T Time in 24 hour format (hh:mm:ss) |
| 39 | +//%U Week where Sunday is the first day of the week (00 to 53) |
| 40 | +//%u Week where Monday is the first day of the week (00 to 53) |
| 41 | +//%V Week where Sunday is the first day of the week (01 to 53). Used with %X |
| 42 | +// %v Week where Monday is the first day of the week (01 to 53). Used with %X |
| 43 | +// %W Weekday name in full (Sunday to Saturday) |
| 44 | +//%w Day of the week where Sunday=0 and Saturday=6 |
| 45 | +// %X Year for the week where Sunday is the first day of the week. Used with %V |
| 46 | +// %x Year for the week where Monday is the first day of the week. Used with %V |
| 47 | +// %Y Year as a numeric, 4-digit value |
| 48 | +// %y Year as a numeric, 2-digit value |
| 49 | + |
| 50 | + /*PHP |
| 51 | + * |
| 52 | + * d Day of the month, 2 digits with leading zeros 01 to 31 |
| 53 | +D A textual representation of a day, three letters Mon through Sun |
| 54 | +j Day of the month without leading zeros 1 to 31 |
| 55 | +l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday |
| 56 | +N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday) |
| 57 | +S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j |
| 58 | +w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) |
| 59 | +z The day of the year (starting from 0) 0 through 365 |
| 60 | +Week --- --- |
| 61 | +W ISO-8601 week number of year, weeks starting on Monday Example: 42 (the 42nd week in the year) |
| 62 | +Month --- --- |
| 63 | +F A full textual representation of a month, such as January or March January through December |
| 64 | +m Numeric representation of a month, with leading zeros 01 through 12 |
| 65 | +M A short textual representation of a month, three letters Jan through Dec |
| 66 | +n Numeric representation of a month, without leading zeros 1 through 12 |
| 67 | +t Number of days in the given month 28 through 31 |
| 68 | +Year --- --- |
| 69 | +L Whether it's a leap year 1 if it is a leap year, 0 otherwise. |
| 70 | +o ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999 or 2003 |
| 71 | +Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 |
| 72 | +y A two digit representation of a year Examples: 99 or 03 |
| 73 | +Time --- --- |
| 74 | +a Lowercase Ante meridiem and Post meridiem am or pm |
| 75 | +A Uppercase Ante meridiem and Post meridiem AM or PM |
| 76 | +B Swatch Internet time 000 through 999 |
| 77 | +g 12-hour format of an hour without leading zeros 1 through 12 |
| 78 | +G 24-hour format of an hour without leading zeros 0 through 23 |
| 79 | +h 12-hour format of an hour with leading zeros 01 through 12 |
| 80 | +H 24-hour format of an hour with leading zeros 00 through 23 |
| 81 | +i Minutes with leading zeros 00 to 59 |
| 82 | +s Seconds with leading zeros 00 through 59 |
| 83 | +u Microseconds (added in PHP 5.2.2). Note that date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds. Example: 654321 |
| 84 | +v Milliseconds (added in PHP 7.0.0). Same note applies as for u. Example: 654 |
| 85 | +Timezone --- --- |
| 86 | +e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores |
| 87 | +I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. |
| 88 | +O Difference to Greenwich time (GMT) in hours Example: +0200 |
| 89 | +P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00 |
| 90 | +T Timezone abbreviation Examples: EST, MDT ... |
| 91 | +Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 |
| 92 | +Full Date/Time --- --- |
| 93 | +c ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00 |
| 94 | +r » RFC 2822 formatted date Example: Thu, 21 Dec 2000 16:01:07 +0200 |
| 95 | +U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) See also time() |
| 96 | + */ |
| 97 | +// } |
| 98 | + |
| 99 | + return date($format, strtotime($date)); |
| 100 | + }; |
| 101 | + } |
| 102 | +} |
0 commit comments