PHP - MYSQL - Dates
Discussion
Aargh, I've wasted enough time on this. I want a simple form field where I can input dates in a UK format and then swap them to MYSQL's native YYYYMMDD format in the background and sling them in my database.
Has anyone got an example of how to do it? I can pull dates out and format them to my hearts content using date('d-m-Y') but swapping 06/02/2008 to 2008-02-06 ready to input is being a right pain.
Heeelp, I'm going mad
Has anyone got an example of how to do it? I can pull dates out and format them to my hearts content using date('d-m-Y') but swapping 06/02/2008 to 2008-02-06 ready to input is being a right pain.
Heeelp, I'm going mad
The initial code didn't work, however it was an invaluable help as it led me to further investigate the ereg expression and come up with this which also includes some date validation!:
echo "<br>Sample output from the input box <br>";
$date2 = $_POST['Datebox'];
if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})",$_POST['Datebox'], $regs)) {
echo "$regs[3]/$regs[2]/$regs[1]" . "<br>";
If(!checkdate($regs[2], $regs[1], $regs[3])){
echo "There appears to be a problem with the validity of the date entered";
}else {
echo "The entry date appears to be correct ";
}
} else {
echo "Invalid date format: " . $_POST['Datebox'] ."<br>";
echo "Please enter the date in the format dd/mm/yyyy";
}
I *think* on my OS I needed the additional $regs variable, either way, it only blummin works!
I'm not sure I've got the heart to examine mktime after all that
And Ex, I know exactly what you mean, last time I got round it with a .js calendar that did the inputting for me without having to swap variables around
echo "<br>Sample output from the input box <br>";
$date2 = $_POST['Datebox'];
if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})",$_POST['Datebox'], $regs)) {
echo "$regs[3]/$regs[2]/$regs[1]" . "<br>";
If(!checkdate($regs[2], $regs[1], $regs[3])){
echo "There appears to be a problem with the validity of the date entered";
}else {
echo "The entry date appears to be correct ";
}
} else {
echo "Invalid date format: " . $_POST['Datebox'] ."<br>";
echo "Please enter the date in the format dd/mm/yyyy";
}
I *think* on my OS I needed the additional $regs variable, either way, it only blummin works!
I'm not sure I've got the heart to examine mktime after all that
And Ex, I know exactly what you mean, last time I got round it with a .js calendar that did the inputting for me without having to swap variables around
The Excession said:
TheGriffalo said:
If the MySQL bods coulr write a few lines of code to interpret date formats they'd save the whole world a heap of time
What you've got to remember Rob, is that getting it out is a whole lote easier than putting it in! Oh Try PostGreSQL - apparently it's much better, but I've still to convince myself - in fact get it working - still happy to be convinced - it seems there's many on here who rate it
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff