473,396 Members | 1,961 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.

An easy Question should mean an easy answer

I am only asking for my code to do a simple thing but for some reason i
just can't get it to do what i want it to do... it been bugging me all
day!

The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days that there
are between these two dates, inclusive. For example:

01/01/2005
03/01/2005
= 3 days

Also over a month change..

27/03/2005
02/04/2005
= 7 days

I can't see anywhere on the forum a successfull version of this in PHP
code.

please Help!
Thanks
Ben

Jul 17 '05 #1
6 1343
Sorry, as you may well tell i am a newbee.
is ther eanywhere i can get instructions on what to do with this file?
wher eis the location it needs to go and how do i call it?

Thanks for this help

Jul 17 '05 #3
"ben3003" <go****@benhenderson.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am only asking for my code to do a simple thing but for some reason i
just can't get it to do what i want it to do... it been bugging me all
day!

The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days that there
are between these two dates, inclusive. For example:

01/01/2005
03/01/2005
= 3 days

Also over a month change..

27/03/2005
02/04/2005
= 7 days

I can't see anywhere on the forum a successfull version of this in PHP
code.

please Help!
Thanks
Ben

Convert the two dates to a unix timestamp, subtract them, and you'll get
your answers in seconds. As long as both dates are after 1969, you'll be
fine.

-Joe
Jul 17 '05 #4
NC
ben3003 wrote:

The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days
that there are between these two dates, inclusive. For example:

01/01/2005
03/01/2005
= 3 days


Actually, this would be 60 days; 03/01 would be interpreter
as March 1, not January 3...

Anyway, here's what you need:

$date1 = '01/01/2005';
$date1 = '03/01/2005';
$days = round((strtotime("$date2 23:59:59") -
strtotime("$date1 00:00:00")) / (24*60*60));

Cheers,
NC

Jul 17 '05 #5
ben3003 wrote:
I am only asking for my code to do a simple thing but for some reason i
just can't get it to do what i want it to do... it been bugging me all
day!
The complexity of a question is in no way related to how succinctly you
can state the question!

compare:
"Why do we think gravitation and acceleration are equivelant?"

with:

"What is 89 plus 5?"
Finding the difference between dates isn't trivial, although it is a
commonly required task...

The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days that there
are between these two dates, inclusive. For example:

01/01/2005
03/01/2005
= 3 days

Also over a month change..

27/03/2005
02/04/2005
= 7 days

I can't see anywhere on the forum a successfull version of this in PHP
code.

please Help!
Thanks
Ben


Jul 17 '05 #6
On 17 Mar 2005 14:08:58 -0800, "ben3003" <go****@benhenderson.co.uk> wrote:
The user inputs 2 dates on one page. in the form xx/xx/xxxx
I then want the output page to display the amount of days that there
are between these two dates, inclusive. For example:


Check out www.phpclasses.org. A search on 'compare date' turns up a number of
classes that accomplish this sort of thing.

HTH
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Derek Wickersham | last post by:
Easy newbie question. I've searched all the PHP documentation I can find, but can't find an answer. What does the "@" mean, in this context: @mysql_select_db( "scripts");
9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
9
by: Weekend | last post by:
Currently, i want to develope a multiple choice exam website. The content of the test is store in an XML file. I want to carry out some function. Could you tell me which programming language should...
3
by: Oliver Bryant | last post by:
I just finished developing a javascipt component allowing floating captions to appear over HTML elements. If anyone wants to check it out you can see specs and download it from...
5
by: mp141 | last post by:
Hello, I was wondering if there was an easy way for me to calculate the mode for a field of values in one query. I have one field of values say Names and all I want it to return is one record of...
18
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When...
6
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double...
12
by: kostas | last post by:
Hi I was asked to propose an interview question for C/C++ programmers (CAD/CAE software) I came up with the following...
20
by: raylopez99 | last post by:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell (this book is amazing, you must get it if you have to buy but one C# book) as well as Appendix A of Jon Skeet's book, I am going...
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: 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
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...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.