?
Solved

PHP GetYear, GetMonth, &  GetDay Functions

Posted on 2003-03-03
5
Medium Priority
?
28,428 Views
Last Modified: 2007-11-27
Does PHP have GetYear, GetMonth, &  GetDay Functions? For example:

$Date = 2003-3-3;
$Year = GetYear($Date); // yields 2003

and so on . . .
0
Comment
Question by:dbnewbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:laurly
ID: 8056264
no but you can use getdate
http://www.php.net/manual/en/function.getdate.php

$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
echo "$month $mday, $year";


laurly
0
 
LVL 8

Expert Comment

by:us111
ID: 8057544
0
 

Author Comment

by:dbnewbie
ID: 8059949
Laurly,

Your assumption is that I am going to obtain the date from the system. Actually, I am going to get it from a database. Also, it will only contain date information (no time). Will what your suggesting work with that? The field type in the database is Date/Time.
0
 
LVL 15

Accepted Solution

by:
VGR earned 100 total points
ID: 8059963
of just, building from your code :

$Date = '2003-03-03'; // dates should be "complete"
$Year = substr($Date,0,4); // GetYear($Date); // yields 2003
$Month = substr($Date,5,2); // GetMonth($Date);
$Day = substr($Date,8,2); // GetDay($Date);

or (better and that can cope with your existing code) :
$Date = '2003-3-3';
$zarbi=explode('-',$Date);
$Year = $zarbi[0]; // GetYear($Date); // yields 2003
$Month = $zarbi[1];
$Day = $zarbi[2];
0
 
LVL 15

Expert Comment

by:VGR
ID: 8062787
Note that a DATETIME containing no time part is supposed to be called a DATE field :D
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question