Jump to content


Photo

extract month of date


  • Please log in to reply
5 replies to this topic

#1 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 April 2006 - 04:03 PM

i would like to ask how to extract the month from a date?
i saved the date in yyyy/mm/dd format, and how do i need todo in order to know whether the date is in Jan, Feb or so on?

thanks.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 April 2006 - 04:14 PM

You can use a combination of the [a href=\"http://www.php.net/strtotime\" target=\"_blank\"]strtotime()[/a] and [a href=\"http://www.php.net/date\" target=\"_blank\"]date()[/a] functions:
<?php
$date = '2006/06/01';
echo date('F',strtotime($date));
?>

Ken

#3 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 April 2006 - 04:21 PM

thanks alot Ken!

#4 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 April 2006 - 05:08 PM

sorry, i have another question regarding to this. can i save the value of "echo date('F',strtotime($date));" into database? how am i suppose to tht??

thanks

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 April 2006 - 05:21 PM

Instead of echoing the result, assign it to a variable and do whatever you want with it.
<?php
$date = '2006/06/01';
$var = date('F',strtotime($date));
?>

Ken

#6 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 April 2006 - 05:23 PM

it's done. :D

thanks really




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users