/    Sign up×
Community /Pin to ProfileBookmark

isDate isTime

Hi is there a function that will test if a value is a date or a time value in php

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Mar 02.2007 — The closest you get is by using strtotime().

If the function returns anything besides a "-1" (or false, starting with PHP 5.1.0), then you've got a valid date/time... It's a bit iffy, I know...[code=php]<?php
IF (strtotime($str) !== FALSE AND strtotime($str) <> -1) :
// Possibly a valid date/time
ELSE :
// Definitely not a valid date/time
ENDIF;
?>[/code]
Copy linkTweet thisAlerts:
@NogDogMar 03.2007 — If you have the numeric values for year, month, and day (either explicitly or else parsed from the input value), you can use the [url=htp://www.php.net/checkdate]checkdate() function[/url] to verify that it's a legitimate date.
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...