CodeIgniter Forums
Beginner Date Helper Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Beginner Date Helper Question (/showthread.php?tid=12117)



Beginner Date Helper Question - El Forum - 10-06-2008

[eluser]seth.aldridge[/eluser]
Hi,

This is my first time in CI and I had an issue with the Date helper.

This is how my time is printing out:

Code:
2008-11-06 00:00:00

This is what I'm using for the Date Helper:

Code:
<?=mdate("%F %j",$row->Date)?>

This is what I get:

Code:
December 31

Does anyone know what I'm doing wrong?

I don't know much about the Date function so I'm not sure how to fix this issue. A little guidance would be much appreciated.

UPDATE: This is across the board no matter what the time is? Could this be something with my date helper php file or a global setting?

Example URL: http://www.boosthabitatcabarrus.org/

Update 2: This seems to be a global issue because even the PHP date() function returns the same date. The only time this happens is if I try to have it format the date with %F %j. If I remove that it displays the correct date...just not formatted.


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]xwero[/eluser]
What kind of date output are you after?


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]Derek Allard[/eluser]
Check that your $row->Date is not generating December 31, 1969 - as it likely would in the event of an invalid timestamp.


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]seth.aldridge[/eluser]
@xwero:
I am looking for it to display Month Day. It currently displays December 31 no matter what date is used.

@Derek:
The string was manually input into PHPMyAdmin and will echo as
Code:
2008-11-06 00:00:00
or whatever date the event is.

I'm not sure how to check $row->Date beyond that. Is there a setting in the date helper that sets a default?


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]Derek Allard[/eluser]
The date helper is expecting a timestamp. It'll look something like "1223382681". If you need that time format, then you'll need to read up on the PHP date functions such as mktime() and date(), and the others, which can be found off the Date/Time page of php.net.


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]xwero[/eluser]
2008-11-06 00:00:00 is not the expected unix timestamp so you have to convert the sql date format to a unix timestamp. You can do this in a few ways
- mysql : UNIX_TIMESTAMP(date) date;
- php : strtotime($row->Date); or human_to_unix($row->Date)


Beginner Date Helper Question - El Forum - 10-07-2008

[eluser]seth.aldridge[/eluser]
Ahh! That is what I was looking for. I can convert this time to UNIX and then have that number converted...thanks!!!


Beginner Date Helper Question - El Forum - 10-08-2008

[eluser]seth.aldridge[/eluser]
I did the human_to_unix($row->Date); and it converted the date, but now the mdate function is only displaying the timestamp. Do I have to convert the Unix to a string before it can properly read it?

Here is my code:

Code:
<?=$td = human_to_unix($row->Date); mdate("%F %j", $td); ?>

This is what it outputs:

Code:
1225958400

FIXED! - I had to assign mdate() to a variable and then call the variable.