[eluser]err403_love[/eluser]
There's really no way you're going to be able to tell the difference between "DD/MM/YYYY" and "MM/DD/YYYY". For instance 04/05/2008 could be May 4th or Apr 5th and there is really no way you'll be able to decipher between the two unless you force all your users to
input the date in the same way.
I think the best thing to do in this case is have a select menu with the month, then input boxes for the day and year, then you can combine the date into whatever format you need. This is really a must since you're relying on user input, and you can't always guess how they're inputting it.
An example could be:
Code:
<!-- INPUTS (in view) -->
<?=form_open('controller/function')?>
<select name="month">
<option>January</option>
<!-- . more options .-->
</select>
<input name="day" type="text" />
<input name="year" type="text" />
<input type="submit" value="Submit" />
</form>
......
<?php
// Controller
if (isset($_POST['day'])
{
// Will output 'May 15, 2008'
$date = $_POST['month'].' '.$_POST['day'].', '.$_POST['year'];
// Turn date into GMT Unix timestamp if necessary
// Will output '1210824000' which is 5/15/2008 at midnight.
$gmt_date = strtotime($date);
}
?>
Hope this helps. I really don't see any easy way to find out a user's date writing preference.. If this is something that will be fairly involving on a user's end, as in a full-blown profile with a lot of options, your other option could be allow them to choose between how they want to see their dates.
For example:
Code:
// EXAMPLE query, should be much more complex than this.
$query = $this->db->query("
SELECT `date_format`
FROM user_table
WHERE `user_id` = ".$this->userid."
");
// I'm not sure if I've written the $query-> stuff correctly, the Database class in CI confuses me. :)
if ($query->num_rows() == 1)
{
$result = $query->result();
if ($result->date_format == 'DD/MM/YYYY')
{
$datetime = date('d-m-Y', $dateline) // Changes the date into the format needed.
}
elseif ($result->date_format == 'MM/DD/YYYY')
{
$datetime = date('m-d-Y', $dateline) // Changes the date into the format needed.
}
elseif ($result->date_format == 'YYYY/MM/DD')
{
$datetime = date('Y-m-d', $dateline) // Changes the date into the format needed.
}
else
{
$datetime = date('m-d-Y', $dateline) // DEFAULT IF USER DOES NOT HAVE ONE FILLED OUT
}
}
Edit: But then you'd also have to change the "$dateline" beforehand to the local time for that user. I don't show this in the above code.