0

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

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by njm5785
0

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).

0

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

0

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.

0

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

Thanks anyway.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.