- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
It will more likely change to some Thursday in 2030. By 2106 people will probably not even remember this overflow.
Admin
Using dd-mmm-yyyy as in the codeSOD is totally dumb, but I have been known to use yyyy-mm-dd or yyyymmddhhmmss or whatever. As long as you have the largest items before the smaller ones it sorts fine, and it's also easier to take 'bits' of the date out (unlike using 'number of seconds since an arbitrary date'). So you could sort by date simply by using the first 8 characters of a yyyymmddhhmmss field
The only thing it doesn't let you do easily is 'date difference' or calculate ages etc, which 'number of seconds' or date/timestamp fields let you do.
Admin
Until you factor the time users lose with your system. YOU don't do that because they are not from your organization, but don't simply assume your experience extends to everybody.
Admin
I know this is heresy, but ... PHP and regular expressions work perfectly well. Sorting by string rather than number works perfectly well. Just read into memory, cut the string into three, swap the day and year parts, and do a lookup to convert the month part to a two-digit number (using a twelve-way switch statement: PHP does this really well, too...) and voila!
Any contractor who can't be bothered to implement some trivial, thin conversion layer to a PHP-based front end loses, big-time.
Wait ... did I just say that PHP and regular expressions work pefectly well?
Admin
PHP and regular expressions only work perfectly well if you work perfectly well.
Some technologies don't even have that much.
Admin
What happens when they upgrade and the date conversion function finds bad data in the tables. Considering that the data field is a char, who knows how many bad values there are where the -quote- date field -unquote- contains 'Jr' or some other bad data from some long forgotten messed up data import. That can play havoc with some string-to-date conversion functions in some languages.
Saving dates as character is absolutely one of my worst "WTF" pet peeves. The only reason to not use built-in date data types is either incompetence or willful ignorance.
Admin
Admin
"Wait... If the "most recent" contractor declared it unfeasible, then how could "another" contractor get it done? :P"
Perhaps the "mostest recent" contractor is the one we're talking about?
Admin
The fix to this is so simple! I don't understand why he walked away. Simply add a field to the table of type DATE. Write a one-off script to convert the existing CHAR fields to date. Run it. Amend the import function to also convert the dates for newly imported records. Run it.
This will obviously miss a few records (those which have been imported between running the first script and amending the import code). So run the first script again, to be sure. Better put it in a field called "Date2", though, in case overwriting a DATE filed adds the values instead of amending them.
Now you've got a date field which can be used anywhere. You only have one use right now - the report, but other code can be changed to use it on an as-needed basis.
Then you can simply check "Date1" - if it doesn't have a value, check "Date2". We ought to add "date3" for any dates amended by the our system (future-proofing in advance is always best). We should update our first script at this point, to populate Date 3 as well, just in case.
Simple.
Admin
Now this is some WTF! Not only you came up with the same idea as a dozen posters did above (the "create date-field" approach), but you also needed 3 fields. Way to go, genius!!
Wouldn't it be smarter to create Date1, modify the import function, and ONLY THEN run the script that would populate that field? This way you wouldn't lose those few records AND you wouldn't need to check IF Date1 had any value stored AND you wouldn't need Date3 either.
Admin
smash,
it's interesting to try to judge peoples' characters from their posts... rarely is it so easy...
Admin
I did not judge his character, just his eagerness to point a solution before refining it to something easier and smaller.
Was I tough on the fella? Alright, maybe I was, and I'm sorry. But it is better hear it from me than from a coworker or worse yet, his boss.
Admin
Smash,
I meant nothing about what you said about the other gentleman, just about what your tone says about who you are... but your response is polite and conciliatory, your willingness to admit you might have been a bit tough on him is certainly an indication of a reasonable and thoughtful person. Perhaps my first impression was wrong...
Your point about his/her post is probably right, he probably wrote, and submitted that post in a few minutes, without reading every prior post or re-reading it and carefully analyzing what he was about to post. But we all do that at times, and perhaps more so in these type of forums than in other venues. To my mind it's an error best simply ignored. There's an old cliche, which I'm sure I am not remembering exactly correctly, that says more or less, that politeness, and good manners, are the glue that holds society together. Criticising people's actions, or beliefs, or their performance, without embarrassing them, or seeming to attack them, is an art worth pursuing. If a person wishes his criticism to have any positive effect other than making themself appear like an un-civilized know-it-all, it is a necessary skill. There are only a finite number of bridges out there to burn...
My apologies, and best wishes...
Admin
Oh dear -- this brings back (bad) memories. I did some work for The Hecht Company years ago. Came on board after the first programmer took a night train out of town (literally) to try to finish the reports which, supposedly, was all that was left. Same issue. Date data stored as strings, SSN data stored as a string (with embedded dashes) in one table, as a numeric in another, redundant code (if on network do bunch of calculations, else do same calculations all over again, minus the database record lock), etc. etc. I eventually told them that I could not, in good conscience, continue the work since I knew I'd be taking their money for a system that would never work. They would not consider a re-write, so I left. The next guy convinced them that a re-write was required...
Admin
summink like
mysqldump blah -uroot -proot > ~/out.sql
mysql -uroot -proot -dblah
ALTER TABLE course ADD coursedate_new DATE NULL
UPDATE course set coursedate_new = function_that_needs_to_slpit_and_concatinate_the_date_into_the_correct_format(coursedate)
ALTER TABLE course drop column coursedate_new
Admin
You will run into the year 2038 problem
Admin
For all intents and purposes, Oracle stores its dates as a whole number of days (after some epoch elucidated by your link) and a fractional part of a day.
So you can write things like SYSDATE+1 to get tomorrow, or SYSDATE-1 to get yesterday.
Admin
I missed where he said he would store the value in a 32-bit integer.
Admin
Um, I don't get why this is so hard. If the MySQL database is populated with data from Oracle every hour wouldn't is be easier to create a new database column in the MySQL database with a date/time field type?
All the old code could use the wtf column, and the new code could really use a date.
Or did I miss something?
Admin
On other hand : Never touch a running system.
Admin
Wow yeah, that is ugly. Not only is the SQL hard to read (major understatement), but it loses the ability to be optimized with an index.
Admin
yet another example of the average PHP developer's ability to use the right tool for the job..
I've seen PHP devs with 10+ years experience store dates as ticks in a string column in mysql. correct me if I'm wrong, but I'm not sure that will sort correctly. even if it does, the continuous date conversion required to make anything of theirs work was enough of a WTF.
Captcha: opto - I opto never have to do PHP ever again
Admin
reminds me of an old problem: when trying to sort by page number, i wound up with this order: 1,10,11,12...2,20,21...etc. the easiest workaround is to number the first 10 pages "01,02,03"...