/    Sign up×
Community /Pin to ProfileBookmark

php date format

Hi All
Please advise, using the below code date format but when text field is empty it should not display anything, but instead it gives any date, how can i go around with this.

echo $Date4 = date(“D d-M-y”, strtotime($person[‘om20’]));

waiting for reply…..

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@svidgenJun 21.2012 — From http://php.net/manual/en/function.strtotime.php
Returns a timestamp on success, FALSE otherwise.[/QUOTE]

From http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting
Converting to integer

To explicitly convert a value to integer, use either the (int) or (integer) casts. However, in most cases the cast is not needed, since a value will be automatically converted if an operator, function or control structure requires an integer argument. A value can also be converted to integer with the intval() function.

See also: type-juggling.

From booleans

FALSE will yield 0 (zero), and TRUE will yield 1 (one).[/QUOTE]


So, the functions are behaving exactly as they "should." You just have to perform an explicit test on the field before you assume it's meaningful data in the contexts in which you're using it!

[code=php]if ($row['field'] == "") {
// don't operate on the field and/or use a default value
} else {
// operate on the field
}[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyJun 21.2012 — I would revise that to this:

[code=php]
$Date4 = "";
if(!empty($row['field'])) {
$Date4 = date("D d-M-y", strtotime($person['om20']));
}
echo $Date4;
[/code]
Copy linkTweet thisAlerts:
@Prithvi_rajauthorJun 22.2012 — Thank you, got it
×

Success!

Help @Prithvi_raj 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.16,
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,
)...