Jump to content

how to go to current date


Baabu

Recommended Posts

hi there i have been trying to use date functions for some function it worked but not for the current time or date

 

here is my query i m using


query=mysql_query("select * from pls where MONTHNAME(stock_Date)='March' ");

it works for this but how should i use it for current date where as the type of stock_Date is DATETIME

i want it to select from pls all the entires for todays date how should i do...any help

Link to comment
https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/
Share on other sites

Try something like this:

<?php
$query = mysql_query("SELECT * FROM pls WHERE DATE(stock_Date) = '" . date('Y-m-d') . "'");
?>

 

The DATE() function around stock_Date might not be needed, but I placed it there because I don't know if your data type is DATE or DATETIME.

$dt=date('Y-m-d'); 
$dtd=date('d');
$dtm=date('m');
$query=mysql_query("select * from pls where MONTHDAY(stock_Date) ='$dtd' and MONTHNAME(stock_Date)='$dtm' ");

well can anyone tell me that how can i extract the date from stock_Date in the format as the date function does like for $dtd=11 and for $dtm=3 how can i get from stock_Date as its format is also just like $dt

 

If you are using a DATE data type for stock_Date, it is already in the YYYY-MM-DD format by default. If, to be sure, you wrap the column in the DATE() function as I have in my previous post, it will assure that you have it in the YYYY-MM-DD format like your $dt variable. You could even just do it all with MySQL:

SELECT * FROM pls WHERE stock_DATE = CURDATE();

thx for your help mate i just placed $dt and it worked but when i use the query u told me it does not display anything even if i echo query it is displayed like this

select * from pls where stock_Date = CURDATE() 

where as this is way i m using to echo it

echo "select * from pls where stock_Date = CURDATE() ";

but if i use

echo "select * from pls where stock_Date = $dt ";

it displays correctly

 

Regards

Baabu

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.