Welcome Guest, Not a member yet? Register   Sign In
Dateformat convert
#1

[eluser]33cent[/eluser]
Hi,

i'm using jQuery datepicker in my new project, to select date for my entry, and format of the date is dd.mm.yyyy. But, in the database, i want to use format yyyy-mm-dd

Have no idea, how to convert date format "on-the-fly" during insert.
I tried something like: "date" = $this->datemodel->convertdate($_POST['date']); but without success.
#2

[eluser]flaky[/eluser]
Display the date in ISO format. Produces '2007-01-26'.

Code:
$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
#3

[eluser]mehike[/eluser]
this is not answer to question...

right now I'm some answer to.

our country is date format - dd.mm.yyyy
but in database I must save this another way.

I use helper right now for this and this is workiing but it's not good way for this, I know...

if ( ! function_exists('date_to_db')) {
function date_to_db($dat) {
$dat_arr = date_parse($dat);
return $dat_arr['year'].'-'.$dat_arr['month'].'-'.$dat_arr['day'];
}
}

if ( ! function_exists('date_from_db')) {
function date_from_db($dat) {
$dat_arr = date_parse($dat);
if (strlen($dat_arr['month'])==1)
$dat_arr['month'] = '0'.$dat_arr['month'];
if (strlen($dat_arr['day'])==1)
$dat_arr['dat'] = '0'.$dat_arr['day'];
return $dat_arr['day'].'.'.$dat_arr['month'].'.'.$dat_arr['year'];
}
}


I't must be better way....
but I'm not time to search it.
#4

[eluser]Dyllon[/eluser]
Use strtotime() to get a timestamp and use it with date() to get any format you wish.
#5

[eluser]saidai jagan[/eluser]
Use explode
Code:
$dat_arr = explode('-',$date);
return $dat_arr[2].'-'.$dat_arr[1].'-'.$dat_arr[0];
#6

[eluser]danmontgomery[/eluser]
[quote author="Dyllon" date="1263781207"]Use strtotime() to get a timestamp and use it with date() to get any format you wish.[/quote]

This.

Code:
function convert_date($date)
{
  return date('d.m.Y', strtotime($date));
}




Theme © iAndrew 2016 - Forum software by © MyBB