php


date_parse_from_format() returns incorrect year


I'm learning PHP and I've been trying to get a two digit representation of a year from the array returned by the date_parse_from_format() function:
date_default_timezone_set('UTC');
$now = date('d.m.Y G:i:s');
$dateArray = date_parse_from_format("j.n.y H:iP", $now);
echo $dateArray['year'];
When I run this code, it prints 2020 on the browser instead of 14 as I expect. Please what am I missing in this code and how do I get the two digit year representation?
Try this
date_default_timezone_set('UTC');
$now = date('d.m.y G:i:s');
$dateArray = date_parse_from_format("j.n.Y H:iP", $now);
echo $dateArray['year'];
Try This
date_default_timezone_set('UTC');
$now = date('d.m.Y G:i:s');
$n = date ('j.n.y H:iP', strtotime($now)); //Convert to format you want
$dateArray = date_parse_from_format("j.n.y H:iP", $n);
echo '<pre>';
print_r($dateArray);
echo '</pre>';`
edit:
<?php
date_default_timezone_set('UTC');
$now = date('d.m.y G:i:s');
$dateArray = date_parse_from_format("j.n.Y H:iP", $now);
echo $dateArray['year'];
?>
date_parse_from_format() is available only in PHP 5.3,
Check this question as well,
PHP date_parse_from_format( ) alternative in PHP 5.2

Related Links

MYSQL Write to a table based on a value in another table
We need to output this as a static site to be hosted on the clients servers [closed]
sql gone away on insert/update only
Redirect after action, how is it possible?
PHP - removing mulitdimensional array elements but keeping the values
How can i change the timestamp to my own timezone in mysql?
How to make asserts on the content from an Excel file?
magento how to check if an attribute value is assigned to any product
Laravel polymorphic nested relations showing unexplainable behaviour
Google OAuth2 - isAccessTokenExpired() always true
Manipulate JSON in Laravel 5 Middleware
Magento - Products not showing on “not visible individually”
Correct regex to detect font family names from google font link src
How to get year of a movie or TV Show from IMDB [closed]
Android WebView PHP Disable Zoom On User Inputs
Struggling with PHP validation

Categories

HOME
amazon-web-services
visual-studio
xcode
scroll
transactions
visual-studio-2010
amp
ontology
navigation
bittorrent
haxe
mailing-list
swarm
heuristics
sap-fiori
bootstrap-switch
sslhandshakeexception
sql-injection
django-rq
temperature
rest-assured
exe
mixpanel
playframework-2.0
boomi
renderscript
spam
el
spreadsheetgear
tsung
microprocessors
tilemill
mapnik
counting
cloveretl
winrm
restful-architecture
cargo
fastlane
variable-variables
aurelia-http-client
recovery
assert
export-to-pdf
grails-spring-security
get-event-store
fiware-wirecloud
vungle-ads
type-inference
doctrine-extensions
audio-converter
dredd
ssi
django-static-precompiler
scala-breeze
password-hash
winston
sonatype
iptv
connect-direct
fitbit
tablespace
data-management
nsdata
openseadragon
jtag
node-glob
arbre
openshift-cartridge
asp.net-web-api-helppages
unhandled
vdm-sl
compositetype
componentart
adhoc-polymorphism
xcode6.3.1
distributed-r
prism.js
zend-search-lucene
miglayout
cidr
proxy-server
armv6
microformats
office-app
gprof
zotonic
directshow.net
asp.net-mvc-views
bll
channelfactory
regression-testing
uninstaller
powergui
eai
tso

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile