April 23, 2012

Converting php4 date() to php5 date_format()

Question by j-man86

I have the following code:

$date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
for( $day = 1; $day <= date("t", $date); $day++ ) {
     //...
}

When executed it produces the following notice:

Notice: A non well formed numeric value encountered in
/home2/wordprh4/public_html/contenido/themes/bam/events/table-mini.php
on line 53

I would like to convert date(); using php5 date_format() but I’m having some issues…

What’s the correct way to do this?


FYI line 53 is

for( $day = 1; $day <= date("t", $date); $day++ ) {

Answer by Starx

I dont see a need to do this, but You can use date_format() like this

$date = date_create('2012-02-01'); //First you have to create the date
echo date_format($date, 'Y-m-d H:i:s'); //Next simply pass the needed format

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!