Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get the date from a column in database SQL

I have a table column called as VoyageDate and it has values like this: Nov 25, 2021 12:00:00.0 AM. I try to view these dates in the frontend in this format YYYY-MM--DD. To do this I tried like this:

SELECT CAST(GETDATE() AS "VoyageDate") AS "voyageDate"

But it does not work correctly. How can I do this.

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The select should be written like this

SELECT FORMAT(GETDATE(), "YYYY--MM--DD") as "voyageDate";

You need to use function format(), to see the date in expected format.

You can read more here https://www.w3schools.com/sql/func_sqlserver_format.asp

If you are trying to read the value from column in table XXX (you don’t specify it in question so replace the XXX with name of table) then the Select should look like this

SELECT FORMAT(VoyageDate, "YYYY--MM--DD") as "voyageDate" from XXX;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading