Jump to content

[SOLVED] passing a variable into the mysql format_date function


terrypeck36

Recommended Posts

i have a query that is trying to compare the true(real) week ($week = date(W);)

with the week of a date i am trying to pass into the mysql format_date function as a variable (itemdate - type int yyyymmdd) that is stored in a column.

my query is :

$sql = "SELECT * FROM table WHERE  DATE_FORMAT('itemdate', '%U') = $week";

its just not working it doesnt give me an error when i query the db either the value passed back is null so is this a valid way to handle date format??

thanks for your time
well date_format is a mysql function which takes in different parameters, these listed below are a few, i am using the w in my php date function to the get current week

i just dont know if its legitmate passing a variable through the msql date_format function


%U Week (00..53), where Sunday is the first day of the week
%u Week (00..53), where Monday is the first day of the week
%V Week (01..53), where Sunday is the first day of the week; used with %X
%v Week (01..53), where Monday is the first day of the week; used with %x
%W Weekday name (Sunday..Saturday)

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.