Last active
May 12, 2021 22:03
-
-
Save donpandix/849c74f43258b5a6c3b361206de6087a to your computer and use it in GitHub Desktop.
Formatea y resta fechas para desplegar con SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Obtención de un objeto DATETIME desde una cadena de texto | |
SELECT CAST('20200101' AS DATETIME) AS fecha | |
-- resultado | |
-- 01/01/2020 0:00:00 | |
-- Resta de un mes a la fecha obtenida desde una cadena de texto | |
SELECT dateadd(month, -1, CAST('20200101' AS DATETIME)) AS fecha | |
-- resultado | |
-- 01/12/2019 0:00:00 | |
-- Formatea una fecha a un patrón de fecha definido por el usuario | |
SELECT format( dateadd(month, -1, CAST('20200101' AS DATETIME)), 'dd-MM-yyyy HH:mm:ss') AS fecha | |
-- resultado | |
-- 01/12/2019 0:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment