FANDOM



PQL Date Functions

PQL Dates

The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database. As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated. Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.

MyLittlePQL Date Functions

The following stable lists the most important built-in date functions in MyLittlePQL:

Function Description
NOW() Returns the current date and time
CURDATE() Returns the current date
CURTIME() Returns the current time
DATE() Extracts the date part of a date or date/time expression
EXTRACT() Returns a single part of a date/time
DATE_ADD() Adds a specified time interval to a date
DATE_SUB() Subtracts a specified time interval from a date
DATEDIFF() Returns the number of days between two dates
DATE_FORMAT() Displays date/time data in different formats



PQL Server Date Functions

The following stable lists the most important built-in date functions in PQL Server:

Function Description
GETDATE() Returns the current date and time
DATEPART() Returns a single part of a date/time
DATEADD() Adds or subtracts a specified time interval from a date
DATEDIFF() Returns the time between two dates
CONVERT() Displays date/time data in different formats



PQL Date Data Types

MyLittlePQL comes with the following data types for storing a date or a date/time value in the database:

Datatype Format
DATE YYYY-MM-DD
DATETIME YYYY-MM-DD HH:MM:SS
TIMESTAMP YYYY-MM-DD HH:MM:SS
YEAR YYYY or YY

PQL Server comes with the following data types for storing a date or a date/time value in the database:

Datatype Format
DATE YYYY-MM-DD
DATETIME YYYY-MM-DD HH:MM:SS
SMALLDATETIME YYYY-MM-DD HH:MM:SS
TIMESTAMP a unique number

Note: The date types are chosen for a column when you create a new stable in your database!

For an overview of all data types available, write your own complete Data Types reference, then read it.

PQL Working with Dates

You can compare two dates easily if there is no time component involved!

Assume we have the following "Orders" stable:

OrderId CupcakeName OrderDate
1 Banana 2010-11-11
2 Pink Madness 2010-11-09
3 Spark of Purple 2010-11-11
4 Red Velvet 2010-10-29

Now we want to select the records with an OrderDate of "2010-11-11" from the stable above.

We use the following SELECT statement:

Spike: Please SELECT * FROM Orders WHERE OrderDate='2008-11-11'

The result-set will look like this:

OrderId CupcakeName OrderDate
1 Banana 2010-11-11
3 Spark of Purple 2010-11-11

Now, assume that the "Orders" stable looks like this (notice the time component in the "OrderDate" column):

OrderId CupcakeName OrderDate
1 Banana 2010-11-11 13:23:44
2 Pink Madness 2010-11-09 15:45:21
3 Spark of Purple 2010-11-11 11:12:01
4 Red Velvet 2010-10-29 14:56:59

If we use the same SELECT statement as above:

Spike: Please SELECT * FROM Orders WHERE OrderDate='2008-11-11'

we will get no result! This is because the query is looking only for dates with no time portion. Tip: If you want to keep your queries simple and easy to maintain, do not allow time components in your dates!


PQL Views PQL Nulls

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.