i am new at sqlserver and i just started learning it , and i have a question .
**i want an SQL query that can bring up all rows that were added in the past 6 months. in table ‘users’ the date is in field ‘joined’ but its in UNIX time stamp format
**and i want then like another SQL query the same as above but it also with the results sets the field ‘activate’ in each row to ‘yes’
i tried that code :
select * from users where time_of_post is like '07/**/2011'
** = anyday but i can`t implement it right .
Thank you a lot for your help in advance .
What you want to use is the
DATEDIFF()function, and get the difference between today’s day (GETDATE()) and the stored dates (time_of_post). If that is less than or equal to 6 months (as denoted by the first parameter,mm) then that should be what you’re looking for.EDIT:
If you’re looking to use this logic for an
UPDATE, you’d do something like this: