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

SQL DATE return not giving what i INSERTED in the Table

So I have created a table in SQL

I get the same result on 2 different online SQL website IDE I was given to use.

https://sqliteonline.com/

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

and

https://www.jdoodle.com/execute-sql-online/

As you can see on the select query I enter the dates that I get returned are not the ones I inserted. Am I doing something wrong? I’m new to SQL and this is a learning project

CREATE TABLE student (
    STU_NUM CHAR(6),
    STU_SNAME VARCHAR(15),
    STU_FNAME VARCHAR(15),
    STU_INITIAL CHAR(1),
    STU_STARTDATE DATE,
    COURSE_CODE CHAR(3),
    PROJ_NUM INT(2),
    PRIMARY KEY (STU_NUM)
);

and then i insert the data in it in this format:

INSERT INTO student
VALUES ('01', 'Snow', 'Jon', 'E', 2014-04-05, 201, 6),
        ('02', 'Stark', 'Arya', 'C', 2017-07-12, 305, 11),
        ('03', 'Lannister', 'James', 'C', 2012-09-05, 101, 2),
        ('04', 'Lannister', 'Cercei', 'J', 2012-09-05, 101, 2),
        ('05', 'Greyjoy', 'Theon', 'I', 2015-12-09, 402, 14),
        ('06', 'Tyrell', 'Margaery', 'Y', 2017-07-12, 305, 10),
        ('07', 'Baratheon', 'Tommen', 'R', 2019-06-13, 201, 5);


However when I do a return on the database the dates are all messed up

SELECT * FROM student

I get:
        01|Snow|Jon|E|2005|201|6
        02|Stark|Arya|C|1998|305|11
        03|Lannister|James|C|1998|101|2
        04|Lannister|Cercei|J|1998|101|2
        05|Greyjoy|Theon|I|1994|402|14
        06|Tyrell|Margaery|Y|1998|305|10
        07|Baratheon|Tommen|R|2000|201|5

I tried to retrieve all the data from the table expecting a DATE format to be in the form I entered id: YYYY-MM-DD

>Solution :

do it this way.

The difference is the date is in single quotes (‘)

INSERT INTO student
VALUES ('01', 'Snow', 'Jon', 'E', '2014-04-05', 201, 6),
        ('02', 'Stark', 'Arya', 'C', '2017-07-12', 305, 11)
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