0

私はトップ30の音楽チャートを作成しています。

2つのmysql形式の日時の間の週数を取得できますか?お気に入り

から:2013-01-15 11:41:14

現在の日時:2013-02-25 13:41:14

4

6 に答える 6

1

SQL を使用する方が優れていますが、php では次のようになります。

<?php
$datetime1 = new DateTime('2013-01-15 11:41:14');
$datetime2 = new DateTime('2013-02-25 13:41:14');
$interval  = $datetime1->diff($datetime2);
$diff      = $interval->format('%d');
echo (int)$diff/7;
于 2013-02-26T14:01:55.743 に答える
0

mysql で DATEDIFF(date1, date2) 関数を試してください。DATEDIFF() は、指定された 2 つの日付の間の日付を返します。出力から簡単に週を取得できることを願っています。

于 2013-02-26T14:07:31.120 に答える
0

メソッドを使用しstrtotime()て、現在の時刻と MySQL データベースにある時刻の差をカウントできます。

于 2013-02-26T13:55:02.693 に答える
0

を使用して時間を減算しますstrtotime

$difference = strtotime($first_date)-strtotime($second_date);

$weeks = round($difference / 604800 );
于 2013-02-26T13:56:09.743 に答える
0
<?php
$db_time_a = strtotime('2013-01-15 11:41:14');
$db_time_b = strtotime('2013-02-25 13:41:14');

$seconds_in_between = $db_time_a - $db_time_b;

$hours = (int)($seconds_in_between/60/60);
$minutes = (int)($seconds_in_between/60)-$hours*60;
$seconds = (int)$seconds_in_between-$hours*60*60-$minutes*60;

echo 'The time in seconds in between the two times is: '.$seconds_in_between.' (Hours:'.$hours.', Minutes:'.$minutes.', Seconds:'.$seconds.')';
?>

「remainder」を使用して秒を細かく分割し、必要な時間距離に到達するまで、分 (および残りの秒) などを調べることができます。

于 2013-02-26T13:59:16.760 に答える
0

関数はWEEK()クエリに役立ちますか?

私はMysqlをよく知りませんが、次のことを前提としています:

select WEEK(date1-date2) from mytable where name='Ken';
于 2013-02-26T13:59:29.303 に答える