# Date Functions

| Name       | Category       |   | Arguments                                                                                 | Result                                                                                                                                                                                                   | Description                                                                        | Example                                                                                                                                  |
| ---------- | -------------- | - | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Make\_Date | Date Functions |   | NUMBER year, NUMBER month, NUMBER day, \[NUMBER hour], \[NUMBER minute], \[NUMBER second] | DATE                                                                                                                                                                                                     | Creates a date from given year, month, day, hour, minute, and second.              | Make\_Date(2009, 3, 12) will create a date with value 12th March 2009. If time is not specified, then midnight time is taken as default. |
| Date       | Date Functions |   | TEXT format, \[DATEFIELD/TIMESTAMP t]                                                     | <p>TEXT</p><p>Returns a text formatted according to the given format text using the given integer Timestamp or Database Date Field. Timestamp is optional and defaults to the value of current time.</p> | The following characters are recognized in the format parameter text. (see below:) | date(“d-M-Y”, now()) returns 16-Sep-2015                                                                                                 |

#### Date Description:

| Format Character    | Description                                                                                                                                                                                                                                                     | Example returned values                                                                   |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| **Day**             |                                                                                                                                                                                                                                                                 |                                                                                           |
| *d*                 | Day of the month, 2 digits with leading zeros                                                                                                                                                                                                                   | *01* to *31*                                                                              |
| *D*                 | A textual representation of a day, three letters                                                                                                                                                                                                                | *Mon* through *Sun*                                                                       |
| *j*                 | Day of the month without leading zeros                                                                                                                                                                                                                          | *1* to *31*                                                                               |
| *l* (lowercase ‘L’) | A full textual representation of the day of the week                                                                                                                                                                                                            | *Sunday* through *Saturday*                                                               |
| *N*                 | ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)                                                                                                                                                                                     | *1* (for Monday) through *7* (for Sunday)                                                 |
| *S*                 | English ordinal suffix for the day of the month, 2 characters                                                                                                                                                                                                   | <p><em>st</em>, <em>nd</em>, <em>rd</em> or<em>th</em>. Works well with<br><em>j</em></p> |
| *w*                 | Numeric representation of the day of the week                                                                                                                                                                                                                   | *0* (for Sunday) through *6* (for Saturday)                                               |
| *z*                 | The day of the year (starting from 0)                                                                                                                                                                                                                           | *0* through *365*                                                                         |
| **Week**            |                                                                                                                                                                                                                                                                 |                                                                                           |
| *W*                 | <p>ISO-8601 week number of year, weeks starting on Monday (added in PHP<br>4.1.0)</p>                                                                                                                                                                           | Example: *42* (the 42nd week in the year)                                                 |
| **Month**           |                                                                                                                                                                                                                                                                 |                                                                                           |
| *F*                 | A full textual representation of a month, such as January or March                                                                                                                                                                                              | *January* through *December*                                                              |
| *m*                 | Numeric representation of a month, with leading zeros                                                                                                                                                                                                           | *01* through *12*                                                                         |
| *M*                 | A short textual representation of a month, three letters                                                                                                                                                                                                        | *Jan* through *Dec*                                                                       |
| *n*                 | Numeric representation of a month, without leading zeros                                                                                                                                                                                                        | *1* through *12*                                                                          |
| *t*                 | Number of days in the given month                                                                                                                                                                                                                               | *28* through *31*                                                                         |
| **Year**            |                                                                                                                                                                                                                                                                 |                                                                                           |
| *L*                 | Whether it’s a leap year                                                                                                                                                                                                                                        | *1* if it is a leap year, *0* otherwise.                                                  |
| *o*                 | <p>ISO-8601 year number. This has the same value as <em>Y</em>, except that if<br>the ISO week number(<em>W</em>) belongs to the previous or next year, that<br>year is used instead. (added in PHP 5.1.0)</p>                                                  | Examples: *1999* or *2003*                                                                |
| *Y*                 | A full numeric representation of a year, 4 digits                                                                                                                                                                                                               | Examples: *1999* or *2003*                                                                |
| *y*                 | A two digit representation of a year                                                                                                                                                                                                                            | Examples: *99* or *03*                                                                    |
| **Time**            |                                                                                                                                                                                                                                                                 |                                                                                           |
| *a*                 | Lowercase Ante meridiem and Post meridiem                                                                                                                                                                                                                       | *am* or *pm*                                                                              |
| *A*                 | Uppercase Ante meridiem and Post meridiem                                                                                                                                                                                                                       | *AM* or *PM*                                                                              |
| *B*                 | Swatch Internet time                                                                                                                                                                                                                                            | *000* through *999*                                                                       |
| *g*                 | 12-hour format of an hour without leading zeros                                                                                                                                                                                                                 | *1* through *12*                                                                          |
| *G*                 | 24-hour format of an hour without leading zeros                                                                                                                                                                                                                 | *0* through *23*                                                                          |
| *h*                 | 12-hour format of an hour with leading zeros                                                                                                                                                                                                                    | *01* through *12*                                                                         |
| *H*                 | 24-hour format of an hour with leading zeros                                                                                                                                                                                                                    | *00* through *23*                                                                         |
| *i*                 | Minutes with leading zeros                                                                                                                                                                                                                                      | *00* to *59*                                                                              |
| *s*                 | Seconds, with leading zeros                                                                                                                                                                                                                                     | *00* through *59*                                                                         |
| *u*                 | <p>Microseconds (added in PHP 5.2.2). Note that <strong>date()</strong><br>will always generate<em>000000</em> since it takes an integerparameter,<br>whereas DateTime::format()<br>does support microseconds if DateTime<br>was created with microseconds.</p> | Example: *654321*                                                                         |
| **Timezone**        |                                                                                                                                                                                                                                                                 |                                                                                           |
| *e*                 | Timezone identifier (added in PHP 5.1.0)                                                                                                                                                                                                                        | Examples: *UTC*, *GMT*, *Atlantic/Azores*                                                 |
| *I* (capital i)     | Whether or not the date is in daylight saving time                                                                                                                                                                                                              | *1* if Daylight Saving Time, *0* otherwise.                                               |
| *O*                 | Difference to Greenwich time (GMT) in hours                                                                                                                                                                                                                     | Example: *+0200*                                                                          |
| *P*                 | <p>Difference to Greenwich time (GMT) with colon between hours and minutes<br>(added in PHP 5.1.3)</p>                                                                                                                                                          | Example: *+02:00*                                                                         |
| *T*                 | Timezone abbreviation                                                                                                                                                                                                                                           | Examples: *EST*, *MDT* …                                                                  |
| *Z*                 | <p>Timezone offset in seconds. The offset for timezones west of UTC is<br>always negative, and for those east of UTC is always positive.</p>                                                                                                                    | *-43200* through *50400*                                                                  |
| **Full Date/Time**  |                                                                                                                                                                                                                                                                 |                                                                                           |
| *c*                 | ISO 8601 date                                                                                                                                                                                                                                                   | 2004-02-12T15:19:21+00:00                                                                 |
| *r*                 | RFC 2822 formatted date                                                                                                                                                                                                                                         | Example: *Thu, 21 Dec 2000 16:01:07 +0200*                                                |
| *U*                 | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)                                                                                                                                                                                                      |                                                                                           |

| Name      | Category       | Arguments                                  | Result | Description                                                                                                                  | Example                                                                                                                                       |
| --------- | -------------- | ------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Now       | Date Functions |                                            | NUMBER | Returns a 10 digit current timestamp.                                                                                        | Now() will return 1442401200 for 16-Sep-2015 11:00AM                                                                                          |
| Date\_Add | Date Functions | DATEFIELD/TIMESTAMP t, NUMBER n, \[TEXT t] | NUMBER | Performs arithmetic operation on date by adding years, months, weeks, days, hours, minutes, and seconds. (Please see below:) | Date\_Add(input\_date, 2, “d”) will add two days to input date Date\_Add(Make\_Date(2015, 2, 12), 10, “d”)) will return 22nd of February 2015 |

#### Date\_Add Description:

| Format Character | Description | Example returned values                                                                      |
| ---------------- | ----------- | -------------------------------------------------------------------------------------------- |
| *d*              | days        | Date\_Add(input\_date, 2, “d”) will add two days to input date                               |
| *m*              | months      | Date\_Add(input\_date, -1, “m”) will substract one month from input date                     |
| *y*              | years       | Date\_Add(input\_date, 1, “y”) will add one year to input date                               |
| *w*              | weeks       | Date\_Add(input\_date, 3, “w”) will add three weeks to input date                            |
| *h*              | hours       | Date\_Add(input\_date, 12, “h”) will add twelve hours to input date                          |
| *min*            | minutes     | <p>Date\_Add(input\_date, -30, “min”) will substract thrity minutes from input<br>date</p>   |
| *s*              | seconds     | <p>Date\_Add(input\_date, 120, “h”) will add one hundred twenty seconds to input<br>date</p> |

| Name                        | Category       | Arguments                                          | Result  | Description                                                                                                                                                                           | Example                                                                                                                                                                                                      |
| --------------------------- | -------------- | -------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| DateTime\_Diff              | Date Functions | DATEFIELD/TIMESTAMP start, DATEFIELD/TIMESTAMP end | NUMBER  | This function gives the to seconds between two dates.                                                                                                                                 | DateTime\_Diff(\[Start\_Date], \[End\_Date]) will return total seconds between Start\_Date and End\_Date DateTime\_Diff(Make\_Date(2015, 2, 12), Make\_Date(2015, 2, 22)) will return 864000                 |
| Add\_Months                 | Date Functions | DATE d, NUMBER m                                   | DATE    | Adds m months to date d and returns the date. It preserves the day of the original date. If that day is not in the new date, then last day of that month is returned.                 | Add\_Months(\[Sales\_Date], 2) will return a date which is two months after Sales\_Date field Add\_Months(Make\_Date(2015, 5, 12), 2) will 12th July 2015 as date                                            |
| Add\_Years                  | Date Functions | DATE d, NUMBER y                                   | DATE    | Adds y years to date d and returns the date. It preserves the day of the original date. If that day is not in the new month of the new date, then last day of that month is returned. | Adjust\_Years(\[Sales\_Date], 2) will return a date which is two years after Sales\_Date field Adjust\_Years(Make\_Date(2014, 1, 14), 2) will 14th January 2016 as date                                      |
| Day                         | Date Functions | DATE d                                             | NUMBER  | Returns the day of the month of the Date d.                                                                                                                                           | Day(Make\_Date(2015, 3, 28)) will 28                                                                                                                                                                         |
| Day\_Of\_Week               | Date Functions | DATE d                                             | NUMBER  | Returns the number of days by which the given date d follows the first day of the week (Sunday returns 0).                                                                            | Examples: Day\_Of\_Week(Make\_Date(2015, 9, 26)) returns 6 (Saturday) Day\_Of\_Week(Make\_Date(2015, 1, 30)) returns 5 (Friday)                                                                              |
| Day\_Of\_Year               | Date Functions | DATE d                                             | NUMBER  | Returns the number of days by which the given date d follows the first day of the year (January 1 returns 0).                                                                         | Day\_Of\_Year(Make\_Date(2015, 9, 29)) returns 271 Day\_Of\_Year(Make\_Date(2015, 12, 9)) returns 342                                                                                                        |
| First\_Day\_Of\_Month       | Date Functions | DATE d                                             | DATE    | Returns the first day of the month in which the date falls.                                                                                                                           | First\_Day\_Of\_Month(Make\_Date(2015, 10, 13)) 1st October 2015 as Date                                                                                                                                     |
| First\_Day\_Of\_Year        | Date Functions | DATE d                                             | DATE    | Returns the first day of the year in which the date falls.                                                                                                                            | First\_Day\_Of\_Year(Make\_Date(2015, 7, 17)) 1st July 2015 as Date                                                                                                                                          |
| First\_Day\_Of\_Week        | Date Functions | DATE d                                             | DATE    | Returns the first day (Sunday) of the week in which the date falls.                                                                                                                   | First\_Day\_Of\_Week(Make\_Date(2015, 5, 9)) will return 3rd May 2015 as Date                                                                                                                                |
| Is\_Leap\_Day               | Date Functions | DATE d                                             | BOOLEAN | Returns true if Date d is 29th of February.                                                                                                                                           | Is\_Leap\_Day(Make\_Date(2015, 2, 29)) will return false Is\_Leap\_Day(Make\_Date(2016, 2, 29)) will return true                                                                                             |
| Is\_Leap\_Year              | Date Functions | DATE d                                             | BOOLEAN | Returns true if the Date d falls in a leap year.                                                                                                                                      | Is\_Leap\_Year(Make\_Date(2015, 2, 29)) will return false Is\_Leap\_Year(Make\_Date(2016, 2, 29)) will return true                                                                                           |
| Working\_Days\_In\_A\_Month | Date Functions | DATE d, NUMBER weekend\_setting, TEXT holidays     | NUMBER  | <p>Weekend Settings:  </p><p></p><p>1: Saturday, Sunday </p><p>2: Sunday </p><p>3: Friday, Saturday </p><p></p><p>Holidays: Comma separated timestamps</p>                            | <p>working\_days\_in\_a\_month(Make\_Date(2016, 3, 1, 0, 0, 0), 1,””) return 23</p><p></p><p>working\_days\_in\_a\_month(Make\_Date(2016, 3, 1, 0, 0, 0), 1, Make\_Date(2016, 3, 23, 0, 0, 0)) return 22</p> |
