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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.