last day (29 days later) » 

1:16 PM
Hii Burki
 
Hello :-)
Whgat can i do for you?
 
First of all ! Thanks for all your help already
 
You are welcome.
 
You have really helped me out mate
Well, im stuck on a sorting problem
 
yes ?
 
1:22 PM
I now got ORDER BY datum DESC
but the date is not ordering the right way
This is proberly because i dont have the Database set on Date
but on Varchar(255)
 
can you give me an example what a datum record looks like in your DB ?
 
21-07-2015
But it only sorts the first 2 digits
 
well... yes. that will be hard to sort ;-) you don't have a sorting problem, but a design problem. (...)
 
so like:

31-07-2015
30-07-2015
14-08-2015
Yeah I know, but the problem of the date function
its like y/m/d
not d/m/y
 
while it is in theory possible to re-format this on the fly in a (fairly complex) query, it would be a much better idea to re-design your application so it stores the data in the format of YYYY-MM-DD
that way, sorting comes for free. everything else not only is a nuisance to sort, group in ranges and such, it also carries the risk of being misinterpreted
 
1:26 PM
Okay, thats possible
but then the problem occures
How can I transform it into dd/mm/yy
and also for the input
 
you may want to take a look at the (very mighty!) datetime-class in PHP
whenever possible, use this datetime-class to handle dates and times. While it requests a little work at first, you get all kinds of conversions and also date arithmetics practically for free
 
Its not a requested time date
its manually added
Its a database for sended packages
 
is it added into the database by hand, like, through phphmyadmin? or through some sort of (web) interface?
 
web form yes
<input type="text" name="datum" value="<?php echo date("d-m-Y")?>">
The value is in case the package has been sended the same day.
 
okay. then change the web form, so it transforms the user input. If you cannot do that, you could also write a script that is run periodically, reading the database and adding a second column with a machine readable date-time-format
 
1:32 PM
soo like :

in the database its 30072015
but the output on web is 30-07-2015
 
so basically: if possible, transform the datum column and the scripts that use it. or add a second column, where some script reads the manually entered value, and writes the machine readable value into the second column. (this way is ugly, and should only be used if the first way is not available for some reasons)
(and by ugly i mean you will hate yourself for having done that some time in the future... ;-) )
(yes? no? maybe? unclear? :- ) )
 

  last day (29 days later) »