Comparing dates stored as varchar

后端 未结 3 2067
栀梦
栀梦 2020-12-02 01:44

I need to compare dates that are stored in my database as varchar against today\'s date.

Specifically, I need to exclude any records with a date that has passed.

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 02:01

    Other than what people have already suggested that you should never store DATETIME as VARCHAR. Always store it in a DATETIME type column; I think you should change your condition in WHERE

    ScheduleEndDate < '2015/05/31'
    

    To this, in order to get all dates which hasn't passed yet

    ScheduleEndDate >= '2015/05/31'
    

    Your query should look like

    SELECT * FROM tblServiceUsersSchedule 
    WHERE ScheduleEndDate IS NOT NULL
    AND ScheduleEndDate >= '2015/05/31'
    

提交回复
热议问题