Databases: date and time functions

Unfortunately databases don’t all use the same SQL language. In most cases, the notation of SQL queries is roughly the same, however in some cases there are differences, for instance when working with dates and times:

  • SQL Server: getdate()
  • Oracle: sysdate
  • Solid: now()
  • mySQL: now()
  • Access: now

Calculation with dates on various databases also differs. SQL Server has the DateAdd funtion, Oracle has overloaded operators so you can use + to increase dates by default with a number of days. Solid has a particular notation: SELECT {fn timestampadd(SQL_TSI_DAY, 30, now())}, which gets us the current date + 30 days. mySQL uses a similar notation but doesn’t require the {fn} syntax:
SELECT TIMESTAMPADD(DAY, 30, now()).

Geschreven door:

Arnout van der Vorst

Arnout van der Vorst is Identity Management Architect bij Tools4ever en al ruim 10 jaar in dienst. Arnout legt zich als Architect toe op het bedenken en ontwikkelen van nieuwe features, oplossingen en diensten van Tools4ever die aansluiten op de vraag uit de markt. Arnout studeerde Hogere Informatica aan de Hogeschool van Utrecht.
Terug