Quintis555
Quintis555

Reputation: 669

Can a MySQL select query look for specific characters?

Sorry for the unclear title, but I'm not sure how else to word it.

I want to use a select statement like this one

"Select time, value from temp_table where time between '2012-01-01' and
'2012-02-20 23:59:59' group by time"

But I would like to specify that I only want to select rows where the time is on the hour, ie. the time ends in ":00"

I know that in some programming languages use can use something like Right$(string_var, 3) to check the last 3 characters of a string; is there anything like that in MySQL?

Upvotes: 1

Views: 148

Answers (2)

Adeel Mughal
Adeel Mughal

Reputation: 736

you can get last 3 chractors from string using this

<?php
$time = '2012-02-20 23:59:59';
$length = strlen($time);
$characters = 3;
$start = $length - $characters;
$time = substr($time , $start ,$characters);
echo $time; 
?>

Upvotes: 0

user149341
user149341

Reputation:

Better yet, actually, there's a function whose sole purpose is to extract the seconds from a time value:

SELECT time, value FROM temp_table
WHERE time BETWEEN '2012-01-01' AND '2012-02-20 23:59:59'
  AND SECOND(time) = 0
GROUP BY time

Upvotes: 5

Related Questions