两个字符串与时间和工作日之间的差异

I have two times saved in database as

DayTime1 = "Wed 09:00"
DayTime2 = "Wed 13:00"

I want to get the difference between these two dates in minutes.

TIMESTAMPDIFF(MINUTES,DayTime1,DayTime2) return null

I'm not able to get through it. Is there any way to get difference?

Please note, that SELECT STR_TO_DATE("Wed 09:00", "%a %H:%i") returns 0000-00-00 09:00:00 (at least on my local MySql 5.5.16). So if comparing different days, you won't get the correct result.

If given a year and week, the day name will be interpreted to a real date, so comparisons may also span days. For example (though not really elegant, I admit):

SELECT TIMESTAMPDIFF(MINUTE,
    STR_TO_DATE(CONCAT(YEAR(CURDATE()), WEEKOFYEAR(CURDATE()), ' Tue 09:00'), '%x%v %a %H:%i'),
    STR_TO_DATE(CONCAT(YEAR(CURDATE()), WEEKOFYEAR(CURDATE()), ' Wed 13:00'), '%x%v %a %H:%i')
)

Since you also included the php-tag, I'm assuming a PHP solution is valid as well:

$daytime1 = "Wed 09:00";
$daytime2 = "Wed 13:00";
$diff = abs(strtotime($daytime1) - strtotime($daytime2)); //absolute diff in seconds
$diff = $diff / 60; //Difference in minutes

EDIT:

And here is a pure MySQL solution:

SELECT ABS(
    TIME_TO_SEC(
        TIMEDIFF(
            STR_TO_DATE("Wed 09:00", "%a %H:%i"),
            STR_TO_DATE("Wed 13:00", "%a %H:%i")
        )
    )
) / 60

The second parameter, "%a %H:%i"is the date format. If it's always in the format of "First three letters of weekday, space, hour with leading zero, :, minutes" then you can use this format.