PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 22nd, 2002, 12:37 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Date

Hi

I was wondering if anyone would know of a solution to the following:

I have a web site form linked to my database using PHP. I now need to check a date entered by the user with whatever the current date is to check that the event didn't take place more than three years ago.

My problem is that I don't know how to write or access a calender so the system is aware of the current date.

Furthermore, I assume I'd have to have such a calender stored in my database so I could compare the two dates?

Please help, I've no idea what is needed to get around this problem.

Vicki


Reply With Quote
  #2  
Old August 22nd, 2002, 03:39 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: Date


To get the current date just use the date() function.

The result can be formated in differnet ways.

I wouldn't assume that the date is stored in the db if you haven't storded any.

Can you show me the table-structure?

Reply With Quote
  #3  
Old August 22nd, 2002, 05:31 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Date

The table structure is:

$sql = "INSERT INTO test (title,given_name,surname,occupation,income,ni_no, house_name,house_number,street,city,post_code,numb er,acc_day,acc_month,acc_year)

However, I want to check the date of the accident (acc_day, acc_month, acc_year) against the current date.

I only want to submit the information into my table if the date of the accident was within 3 years from the current date.

I hope this makes sence to you.

Vicki

Reply With Quote
  #4  
Old August 22nd, 2002, 05:55 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: Date

Try:

php Code:
Original - php Code
  1.  
  2. <?php
  3. // set accident date example
  4. $acc_day = 23;
  5. $acc_month = 8;
  6. $acc_year = 1999;
  7.  
  8. $threeYearsAgo = mktime (0,0,0, date("m"), date("d"), date("Y")-3);
  9. $accidentDate = mktime (0,0,0, $acc_month, $acc_day, $acc_year);
  10.  
  11. if((int) $accidentDate(int) $threeYearsAgo)
  12. {
  13.     // insert into db
  14.     echo('date valid');
  15. }
  16. ?>




Reply With Quote
  #5  
Old August 22nd, 2002, 06:04 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Date

php Code:
Original - php Code
  1.  
  2. <?
  3. $currentDate = time();
  4.  
  5. // variables must have numerical values
  6. $userDate = mktime (0, 0, 0, $month, $day, $year);
  7.  
  8. $years = 31536000 * 3;
  9.  
  10. // and.. do the math
  11. if($userDate < $currentDate && ($currentDate - $userDate) > $years)
  12. {
  13.     // more than 3 years ago
  14. }
  15. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT