PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

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 Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2012, 10:22 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 22 h 2 m 10 sec
Reputation Power: 70
Can't get checkdate to work!

Hello;
I am calling the checkdate function and send an invalid value as argument (04-30w-2013), but it returns true for some reason! I wonder why! Thanks
PHP Code:
/*The code below prints:
04-30w-2013
Good Date */
public function valid_date($date)
    {
        
$date_format explode('-',$date);
        echo 
$date_format['1']."-".$date_format['2']."-".$date_format['0'];
        if(
checkdate($date_format['1'],$date_format['2'],$date_format['0']))
            {
                echo 
"Good Date";
                return 
true;
            }
        else
            {
                echo 
"Bad Date";
                return 
false;
            }
    } 

Reply With Quote
  #2  
Old November 30th, 2012, 10:45 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,697 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 50 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
checkdate() only validates the numbers: 1 <= month <= 12, 1 <= day <= number of days in that month, and something with the year. It doesn't validate the data type.

Regex the whole string or get the components and ctype_digit them, then checkdate() once you know that you actually have real numbers to use.

Reply With Quote
  #3  
Old November 30th, 2012, 10:55 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 22 h 2 m 10 sec
Reputation Power: 70
Quote:
Originally Posted by requinix
checkdate() only validates the numbers: 1 <= month <= 12, 1 <= day <= number of days in that month, and something with the year. It doesn't validate the data type.

Regex the whole string or get the components and ctype_digit them, then checkdate() once you know that you actually have real numbers to use.
Thank you requinix. That's not good. Bad php. They can improve this.

Reply With Quote
  #4  
Old November 30th, 2012, 11:14 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 22 h 2 m 10 sec
Reputation Power: 70
Quote:
Originally Posted by requinix
checkdate() only validates the numbers: 1 <= month <= 12, 1 <= day <= number of days in that month, and something with the year. It doesn't validate the data type.

Regex the whole string or get the components and ctype_digit them, then checkdate() once you know that you actually have real numbers to use.
How about something like this:
PHP Code:
public function valid_date($date)
    {
        
$date_format explode('-',$date);
        if(!
is_numeric($date_format['0']) || $date_format['0']<date('Y') || $date_format['0']>strtotime("+2 years"))
            {
                
$invalid_year=true;
            }
        if(!
is_numeric($date_format['1']) || $date_format['1']<|| $date_format['0']>12)
            {
                
$invalid_month=true;
            }
        if(!
is_numeric($date_format['2']) || $date_format['2']<|| $date_format['0']>31)
            {
                
$invalid_day=true;
            }
        if(!
checkdate($date_format['1'],$date_format['2'],$date_format['0']))
            {
                
$invalid_date=true;
            }
         if(
$invalid_year==true || $invalid_month==true || $invalid_day==true || $invalid_date==true)
            {
                return 
false;
            } 
        
    } 

Reply With Quote
  #5  
Old December 1st, 2012, 02:31 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,697 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 50 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by zxcvbnm
Thank you requinix. That's not good. Bad php. They can improve this.

Why should they change it to suit you? The function is already clearly documented to take three integer arguments. Its purpose is to validate a potential date, not your string inputs.

Quote:
Originally Posted by zxcvbnm
How about something like this:

A little long-winded but sure, if that works for you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Can't get checkdate to work!

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap