0

I have a table with participants and their timestamps. I built a filter and wanted to search for the date (e.g. 2021-01-24) in the timestamp, but that doesn't work because the datas can only be found, when I search with the time included (e.g. 2021-01-24 10:56:46)

So I would like to find a way where I can search for the date and all participants which took part on that specific day show up.

I tried it with the LIKE %xx% command but that didn't work. And i am new to PHP and really need it for my school project.

Thank you!

Linda
  • 3
  • 2
  • What are you trying to search on? A `datetime` column? – El_Vanja Jan 24 '21 at 19:51
  • Does this answer your question? [How to select date from datetime column?](https://stackoverflow.com/questions/1754411/how-to-select-date-from-datetime-column) – El_Vanja Jan 24 '21 at 19:56
  • Do you mean my column in the database? I have the type=timestamp My Code for the filter is: if (count($_POST)>0 && $_POST["R"]!="") { $sql = " SELECT * FROM tbl_teilnehmer WHERE( RegZeitpunkt='" . $_POST["R"] . "' ) "; } else { $sql = " SELECT * FROM tbl_teilnehmer "; } $antwort = $conn->query($sql)or die("Fehler in der Query: " . $conn->error . "
    " . $sql);
    – Linda Jan 24 '21 at 19:57

2 Answers2

0

If you're only wanting to search for dates try the MySQL date() function like so.

select * from table where date(timestamp_col)=?

This will compare explicitly the date component of the timestamp rather than the full timestamp.

Joshua
  • 1,128
  • 3
  • 17
  • 31
0

You Can Try These For Changing Timestamp Format And Show User Side or Frontend

date_format('2022-12-04 19:53:05','D M Y');//date like Fri Des 2022
             or
date_format('2022-12-04 19:53:05','d-m-Y'); //date like 04-12-2022
             or
date('d-m-Y', strtotime('2022-12-04 19:53:05'));

Example

<?php
$full_date = '2022-12-04 19:53:05';
$formated_date = date('d-m-Y', strtotime($full_date));
echo $formated_date;
//output 04-12-2022
?>