Jump to content

PHP and zeros..


mkosmosports

Recommended Posts

Quick question everyone.

I have retrieved dates in "yyyymm" (%Y%c) format from mysql, then put them into an array. I now want the latest date so naturally I would make use of the max function. Ive noticed something though. The latest date I have in my db is 200701, however php doesnt count the 0 in the month, and it ends up being 20071. Is there any way to avoid that?

Thanks in advance....
Link to comment
https://forums.phpfreaks.com/topic/33429-php-and-zeros/
Share on other sites

Store dates as a unix timestamp or in YYYY-MM-DD.

Mysql will recognize the YYYY-MM-DD format and allow you to do things like finding dates between, date > $somevar, date < $somevar etc.

The best way is to use unix timestamps as there is no debating which date is the earlier/later/equal to with that format.

But to answer your question.. looks like change this

yyyymm" (%Y%c)

to

yyyymm" (%Y%m)

From Mysql Manual...

%m Month, numeric (00..12)
%c Month, numeric (0..12)

Try that
Link to comment
https://forums.phpfreaks.com/topic/33429-php-and-zeros/#findComment-156501
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.