Re: Date calculation gives strange format
Posted in 1997
>> >>>How about: >>> >>> select date(date('1/4/1997') + 1 units month) from uniq; >> >>Thanks for the super-quick answer (got the answer before the question >>got back to me from the list!!). Tried it, and it works fine! > >Sorry to spoil the show, but it won't work on 31st May, 31st August, 31st >October, 31st March, nor the 29th January (most years), 30th and 31st >January (assuming that 1 month is added). > >Dealing with those dates is much harder. > >Yours, >Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> > Thanks again to everyone who has responded on this. The clue is in the question: in my example I have used the first of the month. What I intend doing is this. We have a shell script that we use to call all our database querying shell scripts and ACE reports from a menu system. Where dates are relevant the script prompts for the start date and end date to use in the query. We already have a situation where the user can enter 't' for today, 'y' for yesterday, an integer for the number of days prior to today, '.' for 1/1/90 (before the company started, literally 'the year dot'!) or an explicit date. What we are going to do is make the default end date the last day of the month if the user enters the first of the month for the start date. Hence the question - I now realise that all I have to do is the above calculation for the first day of the next month, and subtract 1 for the last day of the previous month. Pretty neat, huh?! Cheers, Richard.