Alvin Jorge
Alvin Jorge

Reputation: 87

getting month from given date php

given this code to retrieve the date from and date to:

<dl>
        <dt><label for="calendar">Date From:</label></dt>
     <dd><input type="text" name="timestamp" id="calendar1" class="calendarFocus" size="32" maxlength="128" /></dd>
    </dl>

   <dl>
        <dt><label for="calendar">Date To:</label></dt>
        <dd><input type="text" name="timestamp1" id="calendar1" class="calendarFocus" size="32" maxlength="128" /></dd>
    </dl>

how can I get only the month?

**this is the Output format of the date above in timestamp: 13/09/2011 10:05... thanks...

Upvotes: 0

Views: 3385

Answers (2)

SeanCannon
SeanCannon

Reputation: 78006

date('M', strtotime( $timestamp ));

Swap M with any of the following:

  • F -- A full textual representation of a month, such as January or March. (January through December)
  • m -- Numeric representation of a month, with leading zeros (01 through 12)
  • M -- A short textual representation of a month, three letters (Jan through Dec)
  • n -- Numeric representation of a month, without leading zeros (1 through 12)
  • t -- Number of days in the given month (28 through 31)

Upvotes: 7

confucius
confucius

Reputation: 13327

 $date_from = $_POST['timestamp'];
 $month_from = substr($date_from,strpos($date_from,'/'),2);
 $date_to = $_POST['timestamp1'];
 $month_to = substr($date_to,strpos($date_to,'/'),2);

Upvotes: 0

Related Questions