Hello

Today is the first of february and I noticed a bug in my coding.

I use the php date function to give me todays date in an european style: 010210

I then insert this date to a mysql table.

The problem is that the date after being inserted is listed as 10210..

This of course makes my other code go crazy..

How can I get the exact "number" into mysql? The column I'm inserting into is VARCHAR(100). Also tried TEXT but did not help..

Recommended Answers

All 6 Replies

Why do you use a TEXT column to store a DATE value ?

Mysql date structure is YYYY-MM-DD. (I thought that was Euro-style!) It's not configurable. We use MM/DD/YYYY here in the USA, so we have to bend and twist the date into our format.

Anyway, you use the PHP functions strtotime() and strftime() to manipulate the date into whatever format you wish. (see PHP manual).

Yes, you are all correct but since I'm a newbie at php and mysql I was just wondering if there is a way that you can store "010210" in mysql without having to rewrite my code. Sort of a quick fix...

I don't know. Did you try int ?
I know that you can get a leading 0 with decimal using all decimal numbers in a format like decimal 6,6 ,but there is that pesky dot...
In the end, the best way is the right way.
How much re-writing could it be?
That's the beauty of this forum, you can ask a question BEFORE you jump in the deep end.

Yeah, I guess I'll have to go the right way..;) Just a couple of hours of recoding..;)

Thanks anyway.

not sure if you have it figured out yet or not but if not you could make that column a int(6) UNSIGNED ZEROFILL. This should then start your date with a lead 0 if it is not 6 ints long.

I have never used it like that before but i know it works when i am counting and want lead zeros.

ex. 1 would be 000001

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.