This is confusing. I'm creating an index for a MySql table of structure "yyyymm", where "yyyy" is year (e.g. 2011) and "mm" is month (e.g. 02). I acquire them with:

$yyyy = date('Y', time());
$mm = date('m', time());

I subsequently convert them to strings with strval and concatenate them (I've also used the other code below the strval example:

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";

I then insert $edition into a MySql table as an index of char(6) but the result is always reversed. Instead of $edition being yyyymm (e.g. 201102), it ends up being mmyyyy (e.g. 22011). I can't seem to zero pad the mm either.

Recommended Answers

All 2 Replies

Member Avatar for diafol
$yyyy = date('Y', time());
$mm = date('m', time());

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";
echo $edition;

Gives me 201102

Show your SQL query and MySQL table schema

$yyyy = date('Y', time());
$mm = date('m', time());

$edition = strval($yyyy) . strval($mm);
$edition = "$yyyy" . "$mm";
echo $edition;

Gives me 201102

Show your SQL query and MySQL table schema

It's resolved - I did all the above (typical debug stuff) previously and got the same result so I was very confused. Your reply got me thinking that there must be some code being executed that was not obvious. It turns out I had two versions of this code; the base code and the developmental code. Within both versions I was re-entering the code when a particular button was being clicked. Stupidly, in the developmental version, I never changed the name of the module to re-enter on submit. So, I started with the developmental code and re-enterd the base code, which caused the error. Lesson learned. THANKS for helping to get my brain in gear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.