On 04/30/2012 14:28, zilore mumba wrote: > sample input > start_date = > '2012-04-29_00:00:00','2012-04-29_00:00:00','2012-04-29_00:00:00', > end_date = '2012-05-01_00:00:00','2012-05-01_00:00:00','2012-05-01_00:00:00', > > The model would have run on 29th May, to produce a 48hour forecast to 1sr May > 2012. >> When I run it on 30th May it should produce a 48hour forecast to 2nd May, >> i.e. change the entries above so that start_date is 30th and end_date is 2nd >> May as below.
> start_date = > '2012-04-30_00:00:00','2012-04-30_00:00:00','2012-04-30_00:00:00', > end_date = '2012-05-02_00:00:00','2012-05-02_00:00:00','2012-05-02_00:00:00', > > zilore mumba schrieb am 30.04.2012 um 10:14 (-0700): > > I have to automate a modle namelist by replacing the start and end > > date of the model run as per lines below. I have no idea where this data is or what you are doing, but it's an easy matter to take a date and add 86400 to it and format it back out again. use strict; use warnings; use POSIX; use Time::Local; # assuming you have this data in $start_date: my $start_date = '2012-04-29_00:00:00'; # and you want to add 1 day to it # just get date portion because the time doesn't appear to be used (always == 0) # you could split on _ and work both date and time if needed (my $date = $start_date) =~ s/_.*$//; # OK, now convert it to epoch time my @D = split /-/, $date; # OK, we now have the year, month and day in @D # let's convert it to epoch (you could use timegm if UTC time rather than local) # I'm hard coding the time to 0 per example my $epoch = timelocal 0, 0, 0, $D[2], $D[1]-1, $D[0]-1900; # now let's add a day to it $epoch += 86400; # OK, all done, let's format a new date-time string my @tm = localtime $epoch; # get it back from epoch to its pieces my $new_start_date = strftime "%Y-%m-%d_%H:%M:%S\n", @tm; # format it print "start_date=$start_date, new start_date=$new_start_date\n"; __END__ _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs