Jump to content
ramiwahdan

date from timestamp

Recommended Posts

Hi,

I have a table field that has the full timestamp (date and time), I want to select records from DB but after checking the date part only from the timestamp.

Example:

2020-3-10 10:15:00 ---- i want to check if current date is equal to the date part which in this case it is the same.

Thanks.

Share this post


Link to post
Share on other sites

I tried this but it is not getting the date from the timestamp:

$testDate = date($row2['ClockingInDate']);
$curdate = date("Y-m-d");

I am still getting the full date and time for the first variable!

Share this post


Link to post
Share on other sites
Posted (edited)

times.png.ae1ef302965cfececc8141210e192085.png

17 minutes ago, ramiwahdan said:

I tried this but it is not getting the date from the timestamp:


$testDate = date($row2['ClockingInDate']);
$curdate = date("Y-m-d");

I am still getting the full date and time for the first variable!

I tried a better one but i am getting the default value of 1970:

$testDate= date('Y-m-d',$row2['ClockingInDate']);
$curdate = date("Y-m-d");

testDate is getting the default value of 1970...why is that?

Edited by ramiwahdan
update with screen shot

Share this post


Link to post
Share on other sites

Where is ClockingInDate coming from? You mention a timestamp and a timestamp from db - what is where, and what data does everything contain?

Share this post


Link to post
Share on other sites

Show us your query.  The way I would do this would be to use a mysql function to only select the yyyy-mm-dd portion of the timestamp and compare it (in the where clause) to the exact yyyy-mm-dd value you want to find.  To be clear - I would do this IN the query statement itself.

Share this post


Link to post
Share on other sites

SELECT whatever

FROM mytable

WHERE DATE(timestamp) = CURDATE()

Share this post


Link to post
Share on other sites

Or

SELECT DATE(timestamp) = CURDATE() -- true or false

FROM mytable

WHERE whatever

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.