473,396 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Perl Date Function

Hi Code Masters,

I have a function to calculate current date as
Expand|Select|Wrap|Line Numbers
  1. sub currentDate {
  2.     my @timeParts=localtime;
  3.     my ($day, $month, $year) = ($timeParts[3],$timeParts[4],$timeParts[5]);
  4.     return ($month+1)."/".$day."/".($year+1900);
  5. }
  6.  
How do I calculate two months after today's date?

Many thanks.
Aug 29 '10 #1

✓ answered by toolic

Date::Calc

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use Date::Calc qw(Today Add_Delta_YMD Date_to_Text);
  4.  
  5. my @today = Today();
  6. my @date = Add_Delta_YMD(@today, 0,2,0);
  7. print "2 months from now will be: ", Date_to_Text(@date), "\n";
  8.  
  9. __END__
  10.  
  11. 2 months from now will be: Thu 28-Oct-2010

5 3138
toolic
70 Expert
Date::Calc

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use Date::Calc qw(Today Add_Delta_YMD Date_to_Text);
  4.  
  5. my @today = Today();
  6. my @date = Add_Delta_YMD(@today, 0,2,0);
  7. print "2 months from now will be: ", Date_to_Text(@date), "\n";
  8.  
  9. __END__
  10.  
  11. 2 months from now will be: Thu 28-Oct-2010
Aug 29 '10 #2
Cool, thanks very much.
Aug 29 '10 #3
Is there a way that I can get rid of the Thu to simply display as "28-Oct-2010"?
Aug 29 '10 #4
toolic
70 Expert
Read the documentation. The return value of the Date_to_Text function is clearly specified:

Expand|Select|Wrap|Line Numbers
  1. my @today = Today();
  2. my @date = Add_Delta_YMD(@today, 0,2,0);
  3. my $date_fmt = (split /\s+/, Date_to_Text(@date))[1];
  4. print "2 months from now will be: $date_fmt\n";
Aug 30 '10 #5
I really appreciate this, sorry for the laziness this time. I will try to do it myself the next time, thanks.
Aug 30 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
3
by: Sharad Gupta | last post by:
Friends I need a date simple date function that would append the coming month value in my current month like monthname(month(date)) : gives me current month in string i need next month , a...
2
by: ltamisin | last post by:
Hi Im working on a Year(Date) function right now, the output of that function is this "2005", my question is how can i change the format into this "05" Function: Year(Date) Output: 2005...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
6
by: bryan.seaton | last post by:
I have a delete statement that is not doing what I want it to do: Delete from LOG_TABLE where (DATE(LOG_TS)) < (DATE(CURRENT_DATE)- 21 DAYS); It is supposed to delete all records that are 21...
4
by: Christine | last post by:
I am having the strangest problem. I use the Date function in several of my forms and modules in an Access 2000 mdb. Lately, wherever in my code (in this one mdb) I use the Date function, it...
4
by: Patrick McGuire | last post by:
I need to get the current date in vb .NET. In vba I always used the Date() function, and the help in .NET indicates that this function still exists, but I can't seem to find it. The Now()...
2
by: tanichka | last post by:
Hello you helpful folk! Please look at my script and tell me what I am doing wrong! I am cleaning the names of my music files from unnecessary symbols, and the cleaning works fine, however the perl...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.