Search results
Results from the Tech24 Deals Content Network
In MS SQL Server, the 2nd and 3rd parameters are reversed DATEADD(mm, -6, GETDATE()). Not sure if this is the valid syntax for another DB Not sure if this is the valid syntax for another DB – KyleMit ♦
I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this? The reason I want to generate a date 6 months from the current date is to produce a review date. If the user enters data into the system it will have a review date of 6 months from the date they entered the data.
I have table containing one datetime column. I need to return rows for only last 6 months. This can be done by where datetime_column > DATEADD(m, -6, current_timestamp) But how to extend this
Why would you write this this way? It's grotesquely long compared to the answer from 3 years prior, and probably 4-5 times as slow due to the 4-5 additional system calls to generate the same amount of information.
8. You can get last six month's data by subtracting interval of 6 month from CURDATE() (CURDATE() is MySQL function which returns Today's date). SELECT * FROM table. WHERE your_date_field >= CURDATE() - INTERVAL 6 MONTH; Or you can use BETWEEN operator of MySQL as Below:
You can implement very easily an "addMonths" function:. function addMonths(date, months) { date.setMonth(date.getMonth() + months); return date; } addMonths(new Date(), -6); // six months before now // Thu Apr 30 2009 01:22:46 GMT-0600 addMonths(new Date(), -12); // a year before now // Thu Oct 30 2008 01:20:22 GMT-0600
3. If you are only interested in what the month was 6 months ago then try this: import datetime. month = datetime.datetime.now().month - 6. if month < 1: month = 12 + month # At this point month is 0 or a negative number so we add. answered Jul 30, 2015 at 4:34.
So if today was April 12, 2010 it should return October 1, 2009 Some possible solutions I've googled seem overly complex, any suggestions?
1. You don't need to pass time() to strtotime, as it is the default. Apart from that, your approach is correct - except that you take date('d') (which is putting out the day) and not date('m') for the month, so echo date('m', strtotime('+6 month')); should do. Nevertheless, I would recommend using the DateTime way, which John stated.
Try this link to another post which explains this exact question SQL Server 2005: how to subtract 6 month. You refer to the word "exact" date, so you don't need the datediff section, you can just subtract 6 months from the current date using "dateadd" which will give you a precise date. Just remember to correctly type cast else you will have to ...