I have a db that I store dates as int unix times.
When displaying in the crud I would like to display the dates in a nice format such as[b] date("d M Y",$thedate);[/b]
When saving the date, I want to do a [b]strtotime()[/b] conversion so that it is stored in the db as an int.
Is there an easy way to do this? Is there a way to have the field show a nice drop down calender?
Thank you in advance!
How to save dates as int but display in nice format
Started by zurtri, 11 April 2012 - 01:26 AM
- Single Page
Posted 11 April 2012 - 01:26 AM
Posted 17 July 2012 - 20:14 PM
I know this is old but for future reference.
You can change the default input box that grocery will create using a callback:
and then do something like this
I also hadd to add a bit of javascript to the page
for the list view another callback
like this
In my example I was storing date as varchar and needed to handle dates like 600-04-23 so obviously change it to suit.
You can change the default input box that grocery will create using a callback:
$crud->callback_field('dateStart',array($this,'_callback_dateStart'));
and then do something like this
function _callback_dateStart($dateStart)
{
if(empty($dateStart))
{
$d = date("d/m/Y");
}
else
{
list($year,$month,$day) = explode('-',$dateStart);
$d = $day.'/'.$month.'/'.$year;
}
return '<input id="field-dateStart" name="dateStart" value="'.$d.'" maxlength="10" class="datepicker-input" type="text">';
}
I also hadd to add a bit of javascript to the page
$('.datepicker-input').datepicker({
dateFormat: 'dd/mm/yy',
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
for the list view another callback
$crud->callback_column('dateStart',array($this,'_callback_date'));
like this
function _callback_date($date)
{
if(empty($date))
{
$d = date("d/m/Y");
}
else
{
list($year,$month,$day) = explode('-',$date);
$d = $day.'-'.$month.'-2012';
$daymonth = date("dS F", strtotime($d));
}
return (empty($date)) ? '' : $daymonth . ' ' . $year;
}
In my example I was storing date as varchar and needed to handle dates like 600-04-23 so obviously change it to suit.