0

1i have been using html 5's input type="date" and found it very useful. i just wanna know if this is possible:

suppose i chose 1/01/2012 in the date picker

i want to save it on my database (mysql) but i want it to be like this " January 1,2012 "

are there ways to do it and how?

require_once "includes/database.php";

$title=$_POST['txtTitle'];
$old_date  = explode("/",$_POST['txtDate']);
$new_date = $old_date[1].' '.$old_date[0].','.$old_date[2];
$date=$new_date;
$from=$_POST['txtFrom'];
$to=$_POST['txtTo'];
$place=$_POST['txtPlace'];
$details=$_POST['txtDetails'];
$id=$_POST['txtEid'];   

        if($id==""){
            $sql = "INSERT INTO events (event_title,event_date,event_tfrom,event_tto,event_place,event_details) VALUES (:title,:date,:from,:to,:place,:details)";
            $qry = $db->prepare($sql);
            $qry->execute(array(':title'=>$title,':date'=>$date,':from'=>$from,':to'=>$to,':place'=>$place,':details'=>$details));
        }else{
        $sql = "UPDATE events SET event_title=?, event_date=?, event_tfrom=?, event_tto=?, event_place=?, event_details=? WHERE event_id=?";
            $qry = $db->prepare($sql);
            $qry->execute(array($title,$date,$from,$to,$place,$details,$id));
        }

    echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>";
    echo "<script language='javascript' type='text/javascript'>window.open('cms_events.php','_self')</script>";
JB De Asis
  • 43
  • 2
  • 8
  • 2
    Why not save it in the date's default format (YYYY-MM-DD) and then alter the date when it is read from the database? The date will be in a generic mSQL DATE format and thus can have its format easily altered throughout you application. – cbronson Jan 08 '13 at 06:08
  • http://i.imgur.com/kj3c1.png?1 i want to make it like what in that picture shows. but all the date were coming from my database and the date saves in int values. – JB De Asis Jan 08 '13 at 06:13

3 Answers3

1

Using javascript you can do something like this

    <button onclick = "getDate()">click for date</button>
    <script>
    function getDate(){
       var monthsOfYear = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

   var d = new Date();
   var currdate = d.getDate();
   var currmonth = d.getMonth();
   var curryear = d.getFullYear();

   alert(monthsOfYear[currmonth] + " "+currdate+","+curryear);
}

Hope this helps..

saraf
  • 646
  • 4
  • 8
0

You can do that by using some php functions explode.

$old_date  = explode("-",$_POST['date']);

$new_date = $old_date[2].' '.$old_date[1].','.$old_date[0];

echo $new_date;

You will get in this format January 1,2012

Php Geek
  • 1,107
  • 1
  • 15
  • 36
0

This wil work perfectly fine for your code, check it..

$old_date  = explode("-",$date);



$months = array('January'=>"01",'February'=> "02", 'March'=>"03",'April'=>"04",  'May'=>"05", 'June'=>"06", 'July'=>"07", 'August'=>"08",'September'=> "09",'October'=>"10", 'November'=>"11", 'December'=>"12");


$nw_month = array_search($old_date[1],$months);


$new_date = $old_date[2].' '.$nw_month.','.$old_date[0];

echo $new_date;
Php Geek
  • 1,107
  • 1
  • 15
  • 36