开发者

Want to convert and display date in mysql table?

Have a form with 10 jquery ui date picker as follows:

$(function() {
$("#datepicker").datepicker({
minDate: 'today',
maxDate: "+90D",
showOn: "button",
buttonImage: "images/calendar-new2.jpg",
buttonImageOnly: true,
dateFormat: "D, dd M, yy"   
});
});

AND

<input type='text' name='day1' id='datepicker1' value='' maxlength="50" style="color:#999999" readonly="readonly"/>
<input type='text' name='day2' id='datepicker2' value='' maxlength="50" style="color:#999999" readonly="readonly"/>  //like 10 input fields

Its named from day1 to day10. User can pick 10 different dates. and it stores into a mysql database.

insert into postings(name, surname, dob, day1, day2, day3, day4, day5, day6, day7, day8, day9, day10).......

And have php query to dispaly the contents. It will display todays data default and if picks a date from calendar, it shows the data of that particular day.

<?php
$today = date('D, d M, Y');
$sql = "SELECT * FROM programs WHERE day1 = '$today' AND city = 'New York' OR day2 = '$today' AND city='New York' OR day3 = '$today' AND city='New York' OR day4 = '$today' AND city='New York' OR day5 = '$today' AND city='New York' OR day6 = '$today' AND city='New York' OR day7 = '$today' AND city='New York' OR day8 = '$today' AND city='New York' OR day9 = '$today' AND city='New York' OR day10 = '$today' AND city='New York'";
if($_POST!=""){
$mydate = mysql_real_escape_string($_POST['datepick开发者_如何学Cer']);
if($mydate!=""){    
$sql = "SELECT * FROM programs WHERE day1 = '$mydate' AND city = 'New York' OR day2 = '$mydate' AND city='New York' OR day3 = '$mydate' AND city='New York' OR day4 = '$mydate' AND city='New York' OR day5 = '$mydate' AND city='New York' OR day6 = '$mydate' AND city='New York' OR day7 = '$mydate' AND city='New York' OR day8 = '$mydate' AND city='New York' OR day9 = '$mydate' AND city='New York' OR day10 = '$mydate' AND city='New York'";  
}       
}
if($mydate) {
echo "<font class=text2>New York - $mydate</font>";
}
else {
echo "<font class=text2>New York - $today</font>";
}
..........
............
?>

what all my queries are...

1) want to save the date from input

<input type='text' name='day1' id='datepicker1' value='' maxlength="50" style="color:#999999" readonly="readonly"/>

to database as YYYY-MM-DD format. Note: input taking the format as "D, dd M, yy". I want display as "D, dd M, yy" in input, but save as YYYY-MM-DD to database?

2) want to get next 30 days data together?


The solution to your all answer is very easy create date and timestamp. In php the date and time is calculated with numbers and if you type

echo time();

It will show you as

1310810553

Now you store this number as date and time which means the date and time stamp. If you want to have your own time stamp then use, the command to generate time and date stamp.

$future_date = mktime($hours, $minutes, $seconds, $month, $day, $year)
echo $future_date

This will show your future date and to calculate the different zone time use

date_default_timezone_set('your time zone');

If you want to get the date, month, year from time stamp then use the following command

$day = date("d", $c);
$month = date("m", $c);
$year = date("Y", $c);

To display the date and time as per your requirement use this

echo date("d-m-Y H:i:s", $future_date)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜