如果日期在今天或之前,我该如何解决? [英] How can I work out if a date is on or before today?

查看:130
本文介绍了如果日期在今天或之前,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的网页应用程序包含图书馆类型系统,书籍有到期日期。

我的网页上显示了当前日期,只需使用以下内容:

  date_default_timezone_set('Europe / London'); 

$ date = date;
打印$ date(d / m / Y);

我将'date'设置为变量,因为我不知道是否有所作为我在图书馆图书页面的IF声明中使用它。



在这个页面上,我只是输出这些书的到期日,许多有日期尚未到达日期,其他日期大于今天的日期。
基本上,我想要的是到期日期显示为粗体(或强),如果它已经过去今天的日期(系统显示日期)。这是我所想的,并认为会奏效:

  < 
if($ duedate< $ date){
echo'< td>< strong>';
} else {
echo'< td>';
}?>

<?php echo $ date('d / m / Y',$ timestamp);?>< / strong>< / td>

我已将$ timestamp声明为var,将默认MySQL格式的日期转换为英文版。谁能帮我吗?我以为这是非常直接的!

解决方案

尝试:

  if(strtotime($ duedate)< time()){
// oooh,你的书迟了!
}


My web application consists of library type system where books have due dates.

I have the current date displayed on my page, simply by using this:

date_default_timezone_set('Europe/London');

$date = date;
print $date("d/m/Y");

I have set 'date' as a variable because I'm not sure if it makes a difference when I use it in the IF statement you're about see, on my library books page.

On this page, I am simply outputting the due dates of the books, many have dates which have not yet reached todays date, and others which have dates greater than todays date. Basically, all I want is the due date to appear bold (or strong), if it has passed todays date (the system displayed date). This is what I have and thought would work:

<?
if ($duedate < $date) {
  echo '<td><strong>';
} else {
  echo '<td>';
} ?>

<?php echo $date('d/m/Y', $timestamp);?></strong></td>

I have declared $timestamp as a var which converts the date of default MySQL format to a UK version. Can anyone help me out? I thought this would've been very straight forward!

解决方案

try:

if (strtotime($duedate) < time()) {
    // oooh, your book is late!
}

这篇关于如果日期在今天或之前,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆