Date search in database

Hello,
I am using “Time stamp” to record time to database
Sample:
I want to list records dated “2022-07-14”

I did something like below but it was not healthy

        $tarih = '2022-07-14';
        $date = explode("-", $tarih);
        $gun_basla = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
        $gun_bitir = mktime(23, 59, 0, $date[1], $date[2], $date[0]);
        $dahil = " AND created BETWEEN ".$gun_basla." AND ".$gun_bitir." ";

How to do it more accurately

Hi, well if you are already printing them out to somewhere, you could just add a small filter using js and filter any date you want.

A MySql timestamp data type is treated as a formatted string in sql queries -

A TIMESTAMP value is returned as a string in the format ‘YYYY-MM-DD HH:MM:SS’ with a display width fixed at 19 characters.

I would produce the BETWEEN values like this -

$tarih = '2022-07-14';
$gun_basla = "$tarih 00:00:00";
$gun_bitir = "$tarih 23:59:59";

And you should ALWAYS use a prepared query when supplying an external, unknown, dynamic value to the query when it gets executed.

This SQL query updates online class attendance for me when I forgot to reset the column has_been_inc. If has_been_inc > 0, the column attendance won’t be incremented.

Then the student can login, but, if the login time is late, the attendance won’t be incremented or if has_been_inc = 1, attendance won’t go up.

If I forgot to reset has_been_inc, this query saves the day, because the logon time is saved in logon_times_20EAPCW too. (The students often tell, “I came on time.” so I export that row and show them.)

UPDATE logon_times_20EAPCW, allstudents20EAP SET allstudents20EAP.attn_this_week = allstudents20EAP.attn_this_week + 1 WHERE logon_times_20EAPCW.Week17_M > '2022-04-09 13:20:00' AND logon_times_20EAPCW.Week17_M < '2022-04-09 13:30:00' AND allstudents20EAP.studentnr = logon_times_20EAPCW.studentnr

Maybe that will help you!

I want to list records for x days in database.
Since applications like dataTable load all rows, I think rows with large data will cause page lag.

When I mean “time stamp” I mean “1659783290” this record

What is the actual problem you are having?

BTW - you are leaving out 59 seconds worth of values in the posted code. The 23, 59, 0 should be 23, 59, 59

I didn’t see any issues on my local computer but on the remote server I found that sometimes it didn’t return the date I selected
I was wondering if there is a mistake here

I am changing the date from this format “1659783290” to this format “time stamp”

Are you sure it isn’t something else in the WHERE part of the query?

It would take having a $tarih value that doesn’t work and an sql dump of the table definition and the data that should be matched, along with the entire sql query statement.

If the search is the date, I add the following line to the sql query

I’m not sure, but I changed it as you suggested
I added single quotes to dates
It works fine, I hope it always works like this
Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service