You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes when getting a date from a database you might not care about the whole date but just a part of it.
For example, if you have a list of articles and want to give the user a filter option for the year in which the article released, you just care about the year.
At the moment you'd have to get the whole date and then in your application code extract the year from it. This isn't a big deal of course but in SQL you have the EXTRACT(YEAR FROM CURRENT_TIMESTAMP) function.
I think having this function in sqlpp would be useful.
Similarly to #610 there's multiple options for the design of such a function.
Instead of extract you could have multiple functions year_of(date), month_of(date), ... like the functions MySQL has (YEAR(date), MONTH(date), ...).
You could have a templated function extract<datepart::year_t>(date)
You could have a parameter for the datepart and have the template parameter deduced extract(datepart::year, date)
Due to the EXTRACT(datepart FROM date) function being standardized I strongly prefer the latter two.
-Jonas
The text was updated successfully, but these errors were encountered:
Sometimes when getting a date from a database you might not care about the whole date but just a part of it.
For example, if you have a list of articles and want to give the user a filter option for the year in which the article released, you just care about the year.
At the moment you'd have to get the whole date and then in your application code extract the year from it. This isn't a big deal of course but in SQL you have the
EXTRACT(YEAR FROM CURRENT_TIMESTAMP)
function.I think having this function in sqlpp would be useful.
Similarly to #610 there's multiple options for the design of such a function.
year_of(date)
,month_of(date)
, ... like the functions MySQL has (YEAR(date)
,MONTH(date)
, ...).extract<datepart::year_t>(date)
extract(datepart::year, date)
Due to the
EXTRACT(datepart FROM date)
function being standardized I strongly prefer the latter two.-Jonas
The text was updated successfully, but these errors were encountered: