Mysql date_add returns wrong row in python, right row in phpmyadmin
First, a crucial mistake of the queries:


LIMIT without ORDER BY does not guarantee consistent results.
If you get correct results using LIMIT without ORDER BY, it's only by accident.


The results you got from running the queries in PHPMyAdmin was only accidental. There is no guarantee that you'll get the same results if you run the same queries tomorrow. 

Adding ORDER BY (either ASC or DESC) will solve the issue.

There is also another problem with the 1st query. Adding 25 hours instead of 24 might be a nice hack - if it worked. It might work with the current data but it will stop, if there are ever rows that are not limited to full hours or there are no rows for the first hour of a month. You need to use 24 hours (or 1 day) and timestamp &gt;= ... and ORDER BY .. ASC to get the first row from a period.

Queries rewritten (I used date arithmetic instead of your DATE_ADD(), this is entirely personal preference, the DATE_ADD() is fine in your queries):

-- First row in previous month (or later)
SELECT * 
FROM mcs 
WHERE time_stamp &gt;= LAST_DAY(NOW()) + INTERVAL 1 DAY + INTERVAL -2 MONTH 
  AND wot_id = 1010965979
ORDER BY time_stamp ASC
LIMIT 1 ;

-- Last row in previous month (or earlier)
SELECT * 
FROM mcs 
WHERE time_stamp &lt;  LAST_DAY(NOW()) + INTERVAL 1 DAY + INTERVAL -1 MONTH 
  AND wot_id = 1010965979
ORDER BY time_stamp DESC 
LIMIT 1 ;