Skip to content
Permalink
Browse files

Add data and time function help

  • Loading branch information
NathanW2 committed Jul 22, 2012
1 parent 0cd93a2 commit 304a6251be5c3527c23749293ce090b6ca82b79e
@@ -0,0 +1,12 @@
<h3>$now function</h3>
Returns the current data and time

<h4>Syntax</h4>
<pre>$now</pre>

<h4>Arguments</h4>
None
<h4>Example</h4>
<!-- Show example of function.-->
<pre>$now -> 2012-07-22T13:24:57</pre>

@@ -0,0 +1,2 @@
<h3>Date and Time Group</h3>
This group contains functions for handling date and time data.
@@ -0,0 +1,32 @@
<h3>age() function</h3>
Returns the difference between two dates.
<br><br>
The difference is returned as a <code>Interval</code>
and needs to be used with one of the following functions
in order to extract useful information:
<pre><code>
- year
- month
- week
- day
- hour
- minute
- second
</code></pre>
<h4>Syntax</h4>
<code>age(string,string)</code><br>
<code>age(datetime,datetime)</code><br>
<code>age(string,datetime)</code><br>
<code>age(datetime,string)</code><br>

<h4>Arguments</h4>
<code>string</code> - is string. A sting in date format.
<br>
<code>datetime</code> - is date or datetime. A date or datetime type.

<h4>Example</h4>
<!-- Show example of function.-->
<code>age('2012-05-12','2012-05-2') -> Interval</code><br>
use <code>day</code> to extract numbder of days<br>
<code>day(age('2012-05-12','2012-05-2')) -> 10</code><br>

@@ -0,0 +1,19 @@
<h3>day() function</h3>
Extract the day from a date, or the number of days
from a <code>Interval</code>

<h4>Syntax</h4>
<code>day(date)</code><br>
<code>day(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is date or datetime. The date to extract the day from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of days from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>day('2012-05-12') -> 12</code><br>
<code>day(tointerval('3 days')) -> 3</code><br>
<code>day(age('2012-01-01','2010-01-01')) -> 730</code><br>

@@ -0,0 +1,20 @@
<h3>hour() function</h3>
Extract the hour from a datetime or time, or the number of hours
from a <code>Interval</code>

<h4>Syntax</h4>
<code>hour(datetime)</code><br>
<code>hour(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is datetime or time. The date to extract the hour from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of hours from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>hour('2012-07-22T13:24:57') -> 13</code><br>
<code>hour(tointerval('3 hours')) -> 3</code><br>
<code>hour(age('2012-07-22T13:00:00','2012-07-22T10:00:00')) -> 3</code><br>
<code>hour(age('2012-01-01','2010-01-01')) -> 17520</code><br>

@@ -0,0 +1,20 @@
<h3>minute() function</h3>
Extract the minute from a datetime or time, or the number of minutes
from a <code>Interval</code>

<h4>Syntax</h4>
<code>minute(datetime)</code><br>
<code>minute(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is datetime or time. The date to extract the minute from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of minutes from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>minute('2012-07-22T13:24:57') -> 24</code><br>
<code>minute(tointerval('3 minutes')) -> 3</code><br>
<code>minute(age('2012-07-22T00:20:00','2012-07-22T00:00:00')) -> 20</code><br>
<code>minute(age('2012-01-01','2010-01-01')) -> 1051200</code><br>

@@ -0,0 +1,19 @@
<h3>month() function</h3>
Extract the month part from a date, or the number of months
from a <code>Interval</code>

<h4>Syntax</h4>
<code>month(date)</code><br>
<code>month(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is date or datetime. The date to extract the month from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of months from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>month('2012-05-12') -> 05</code><br>
<code>month(tointerval('3 months')) -> 3</code><br>
<code>month(age('2012-01-01','2010-01-01')) -> 4.033...</code><br>

@@ -0,0 +1,20 @@
<h3>second() function</h3>
Extract the seconds from a datetime or time, or the number of seconds
from a <code>Interval</code>

<h4>Syntax</h4>
<code>second(datetime)</code><br>
<code>second(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is datetime or time. The date to extract the second from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of seconds from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>second('2012-07-22T13:24:57') -> 57</code><br>
<code>second(tointerval('3 seconds')) -> 3</code><br>
<code>second(age('2012-07-22T00:20:00','2012-07-22T00:00:00')) -> 1200</code><br>
<code>second(age('2012-01-01','2010-01-01')) -> 63072000</code><br>

@@ -0,0 +1,19 @@
<h3>week() function</h3>
Extract the week number from a date, or the number of weeks
from a <code>Interval</code>

<h4>Syntax</h4>
<code>week(date)</code><br>
<code>week(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is date or datetime. The date to extract the week from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of weeks from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>week('2012-05-12') -> 19</code><br>
<code>week(tointerval('3 weeks')) -> 3</code><br>
<code>week(age('2012-01-01','2010-01-01')) -> 104.285...</code><br>

@@ -0,0 +1,19 @@
<h3>year() function</h3>
Extract the year part from a date, or the number of years
from a <code>Interval</code>

<h4>Syntax</h4>
<code>year(date)</code><br>
<code>year(Interval)</code><br>

<h4>Arguments</h4>
<code>date</code> - is date or datetime. The date to extract the year from.
<br>
<code>Interval</code> - is Interval. The Interval to return the number of years from.

<h4>Example</h4>
<!-- Show example of function.-->
<code>year('2012-05-12') -> 2012</code><br>
<code>year(tointerval('3 Years')) -> 3</code><br>
<code>year(age('2012-01-01','2010-01-01')) -> 1.9986..</code><br>

@@ -756,16 +756,16 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
<< FunctionDef( "totime", 1, fcnToTime, QObject::tr( "Conversions" ) )
<< FunctionDef( "tointerval", 1, fcnToInterval, QObject::tr( "Conversions" ) )
<< FunctionDef( "coalesce", -1, fcnCoalesce, QObject::tr( "Conversions" ) )
// date/time
<< FunctionDef( "$now", 0, fcnNow, QObject::tr( "Date/Time" ) )
<< FunctionDef( "age", 2, fcnAge, QObject::tr( "Date/Time" ) )
<< FunctionDef( "year", 1, fcnYear, QObject::tr( "Date/Time" ) )
<< FunctionDef( "month", 1, fcnMonth, QObject::tr( "Date/Time" ) )
<< FunctionDef( "week", 1, fcnWeek, QObject::tr( "Date/Time" ) )
<< FunctionDef( "day", 1, fcnDay, QObject::tr( "Date/Time" ) )
<< FunctionDef( "hour", 1, fcnHour, QObject::tr( "Date/Time" ) )
<< FunctionDef( "minute", 1, fcnMinute, QObject::tr( "Date/Time" ) )
<< FunctionDef( "second", 1, fcnSeconds, QObject::tr( "Date/Time" ) )
// Date and Time
<< FunctionDef( "$now", 0, fcnNow, QObject::tr( "Date and Time" ) )
<< FunctionDef( "age", 2, fcnAge, QObject::tr( "Date and Time" ) )
<< FunctionDef( "year", 1, fcnYear, QObject::tr( "Date and Time" ) )
<< FunctionDef( "month", 1, fcnMonth, QObject::tr( "Date and Time" ) )
<< FunctionDef( "week", 1, fcnWeek, QObject::tr( "Date and Time" ) )
<< FunctionDef( "day", 1, fcnDay, QObject::tr( "Date and Time" ) )
<< FunctionDef( "hour", 1, fcnHour, QObject::tr( "Date and Time" ) )
<< FunctionDef( "minute", 1, fcnMinute, QObject::tr( "Date and Time" ) )
<< FunctionDef( "second", 1, fcnSeconds, QObject::tr( "Date and Time" ) )
// string manipulation
<< FunctionDef( "lower", 1, fcnLower, QObject::tr( "String" ) )
<< FunctionDef( "upper", 1, fcnUpper, QObject::tr( "String" ) )

0 comments on commit 304a625

Please sign in to comment.
You can’t perform that action at this time.