473,748 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

comparing dates (perl - mysql)

2 New Member
Is there an easy way to calculate how many days between two dates..

i have two dates and want to work out how many days between them, i have a static date and was getting todays date then working out for each what the day of the year was and subtracting the two, this worked fine until the new year.. now i have dates from 2006 and todays date of 2007 and obviously cant use the day of the year function as the 2007 date is less than the 2006 date...

i simply want to calculate number of days from a date in the past to the current date...

last year i suffered a stroke and have forgot a lot of my programming so any help whatsoever would be greatly appreciated and will stop me banging my head against a wall which isn't good either...

thanks in advance
Cyber
Jan 4 '07 #1
2 4145
miller
1,089 Recognized Expert Top Contributor
In perl, use the Delta_Days function from the Date::Calc module:

http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod

Expand|Select|Wrap|Line Numbers
  1. use Date::Calc qw(Delta_Days);
  2.  
  3.       $Dd = Delta_Days($year1,$month1,$day1,
  4.                        $year2,$month2,$day2);
  5.  
In MySQL, use the DATEDIFF function

http://www.mysql.org/doc/refman/5.1/...functions.html
Jan 4 '07 #2
cyber100
2 New Member
Thanks mate, works a treat, many thanks
Jan 6 '07 #3

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

Similar topics

45
16908
by: Market Mutant | last post by:
I just wonder job selections, job openings and salary level of PHP programer or Perl programmer comparing to Java programmers. Is Java programmer's salary has a minimal of 60K in US? Are there many PHP jobs?
4
2411
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution. http://www.aspfaq.com/show.asp?id=2023 Now I am facing another problem. I have to get data between two dates. That dates user has to provide and in
0
1393
by: John Ntow | last post by:
I have a binary distribution of MySQL 4.0.20 installed in /usr/local/mysql. Therefore, the only libmysqlclient file I have is libmysqlclient.a (static library). And also, Perl:DBI already installed. I'm trying to install perl-DBD-MySQL-2.9004 from source. What should I add to 'perl Makefile.PL' as arguments to make sure it finds the static library?
1
3824
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /home/alex/.cpan/Metadata Database was generated on Mon, 29 Nov 2004 16:01:05 GMT Running install for module DBD::mysql Running make for R/RU/RUDY/DBD-mysql-2.9004.tar.gz CPAN: Digest::MD5 loaded ok
1
3640
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is produced due to the unknown GCC compiler option "+DAportable". For the Build using CC, the preprocessor error is produced due to the recursive declration of macro "PerlIO" in perlio.h file.
6
3444
by: Taxi Driver | last post by:
Hi Everyone - Can I get your help with this, it is driving me crazy. I have 2 arrays listed below: @req=75 @req=76 @req=77 @req=78 --- @bid=75 @bid=76
2
18333
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is newer than the last user login, then I need for a message to pop up and say New Comments. If not, then no new comments. The area of this code which is not working is at the bottom.
4
2353
by: cheryl | last post by:
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.......
11
6191
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
0
8983
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.