Gossamer Forum
Quote Reply
show future date
I'm not having much success trying to create a global that will show the date (in YYYY-MM-DD format) six months from the current date. I think I'm making this much harder than it is. Here is the global for showing the current date:
Code:
sub {
# Displays the current date.
Links::init_date();
GT::Date::date_set_format($CFG->{'date_user_format'});
my $date = GT::Date::date_get();
GT::Date::date_set_format($CFG->{'date_db_format'});
return $date;
}


Any ideas on how to show six months from current date (YYYY-MM-DD)?
Quote Reply
Re: [kysa] show future date In reply to
I'm sorry to be non-GT library but here's how I'd do it:

Code:
sub {
require POSIX; import POSIX qw/strftime/;
return POSIX::strftime("%Y-%m-%d", localtime(time() + 15552000));
}

The 15552000 assumes there are 30 days in a month.
Quote Reply
Re: [Paul] show future date In reply to
thank you VERY much paul!... one more quickie (sorry), to help me learn these date manipulation techniques... what would the global look like if i wanted to show some future date from the Add Date field (ie. say 6 months added to the Add Date), as opposed to today's date?
Quote Reply
Re: [kysa] show future date In reply to
I've just had a quick peek at the GT::Date docs so don't take this as gospel, but I think you can do something like:

my $new_date = date_add($the_original_date, 30 * 6);
Quote Reply
Re: [Paul] show future date In reply to
the following global works to calculate 180 days (30days*6months) from today

Code:
sub {
# Displays six months from today.
Links::init_date();
my $date1 = GT::Date::date_get();
my $date2 = GT::Date::date_add($date1, 30 * 6);
GT::Date::date_set_format($CFG->{'date_db_format'});
return $date2;
}


the problem is that i cannot assume 30 days for every month... what i really need is to add 6 months (ie. if it is 2003-02-22, then return 2003-08-22), not 180 days... i can't create an array out of month and add six (ie. 11 + 6 = 17... a nonsensical month)... any thoughts on how can i calculate 6 months and display in YYYY-MM-DD format?... i've reviewed the GT::Date help, but don't see this issue addressed... thanks in advance
Quote Reply
Re: [kysa] show future date In reply to
You need to do a bit of date arithmetic. Parse the date into mm-dd-yy type format, then add 6 to the mm. If greater than 12 (or 11 if zero based) then subtract 12. Put the date string back together, and you have added 6 calendar months.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] show future date In reply to
yes... it is the parsing of a date that i 've tried and failed at miserably... any ideas?