I researched the forum but could not find a solution.
I have a date in my DB and date format is not like Y-m-d H:i
. And the table is not set as date. I need to fetch the date from db but I just need Y-m-d
. My date format like: 9.12.2014 18:34
. I just need 9.12.2014
. I want my query to stop when it sees the blank/space. I'm fine with the d.m.Y
format.
Is there a way?
I think I found the solution:
$email = 'name@example.com';
$user = strstr($email, '@', true); // after PHP 5.3.0
echo $user; // name
This should account for most scenarios; you will get the whole string if there are no spaces:
SELECT IF(INSTR(field, ' ')=0, field, LEFT(field, INSTR(field, ' ')-1))
FROM the_table
;