简体   繁体   中英

Issue in fetching record from database

I have a field name "date" datatype "char" and value in thid field is "04-08-2011 04:47:08 EDT" but when i want to fetch the records from our data base basis on date like

select * from table_name where date="04-08-2011 04:47:08 EDT"

but i dont get any result for this query,any one can help me

Try using the LIKE statement, because if your field has X chars and you insert X-3 chars, the 3 left chars are filled with spaces, so modify your query to be like:

select * from table_name where date LIKE "04-08-2011 04:47:08 EDT%"

EDIT: date is a field type in MySQL, so this query isn't valid. If your field is 'date', you need to put it between ``, so the query will be like this:

select * from table_name where `date`="04-08-2011 04:47:08 EDT"

If you're using the datatype char then any characters that are under the set length of the column will be right padded with spaces.

eg

char (30) would pad like so:

04-08-2011 04:47:08 EDT     <-- spaces up to arrow

Use a date datatype or varchar (if you must).


In response to comment:

Have you run this query from phpMyAdmin? If so, does it return any rows, if not, try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM