The following is a MYSQL script:
I have the following script to put a “1” in the field IF the tstamp date falls within the current week’s Sunday to Saturday, but instead it goes back to all years, and inserting a 1, instead of just for the current year.
Any ideas?
IF(FROM_UNIXTIME(renprop_commercial_new.tstamp, "%U") = FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()),"%U"),1,0)
Since %U only returns the week-of-year, regardless of which year the timestamp is actually in, you also need to compare years. Easiest way to do that is by using
%Y-%Uas your format string. That’ll give you (say)2012-23instead of just23.However, note that this will only be reliable if you’re doing equality comparisons. If you start doing greater-/less-than comparisons, something like
2012-2while evaluate as “greater” than2012-13, because the comparison will done as a string, not numerically.