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

Link to comment
Share on other sites

$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

 

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.