how to extract month from given date by using string
functions?

Answers were Sorted based on User's Feedback



how to extract month from given date by using string functions?..

Answer / guest


print strftime('%B',time());

This will return the name of the current month.
And date('M') also will return current month.

If you want to get month from the date then use the
following way.

$date=date('d/M/Y')
$date=substr($date,strpos($date,'/')+1);
$date=substr($date,0,strpos($date,'/'));

Finally $date will contain the month name.

Is This Answer Correct ?    2 Yes 0 No

how to extract month from given date by using string functions?..

Answer / subodh

Assume date is like $datestr = '01-12-2013';
then it can be below two ways:
1. echo date('M', strtotime($datestr)); // for textual
// Or date('m', strtotime($datestr)); // for numeric
2. $list($d, $m, $y) = explode('-', $datestr);
echo $m; // for numeric

Is This Answer Correct ?    0 Yes 0 No

how to extract month from given date by using string functions?..

Answer / pavunkumar

use this code.


[code]
?php
print date ( 'm',mktime ( 0,0,0,02,26,2010 ) ) ;
?>
~
[/code]

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More PHP Interview Questions

How many ways there are to fetch the data from the Database?

2 Answers   Tops Technologies,


Is php coding easy?

0 Answers  


What is a php class?

0 Answers  


What is the use of super-global arrays in php?

0 Answers  


Write a program to find a string is palindrome or not?

0 Answers  


What is the difference between mysql_connect and mysql_pconnect ? Which one is good in terms of performance ?

4 Answers  


Which function would you use to insert a record into a database in php?

0 Answers  


How to merge values of two arrays into a single array?

0 Answers  


Who is the father of PHP and explain the changes in PHP versions?

15 Answers   ADISoft Tech, Genpact, PropTiger, TWA,


What is difference between required and require_once in php?

0 Answers  


Why php is used?

0 Answers  


Describe the security vulnerability of PHP?

0 Answers  


Categories