Re: date problem
| From: | Jonathan Sundquist | Date: | Thu, 03 Jan 2013 22:15:47 +0000 |
| Subject: | Re: date problem | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320023@lists.php.net to get a copy of this message | ||
Marc,
When you take a date and do a strtotime you are converting it to an int
which you can compare to each other much easier. So for your above example
you would be best doing.
define('WSOFFBEGIN','09/16/2012');
$jes = 01/03/2012;
if ( strtotime($jes) < strtotime(WSOFFBEGIN) )
{
$error = " MUST begin after " . WSOFFBEGIN . "\n";
}
On Thu, Jan 3, 2013 at 4:12 PM, Marc Fromm <Marc.Fromm@wwu.edu> wrote:
> Thanks for the reply.
>
> Every example on comparing dates in PHP that I found uses the "strtotime"
> function which I am using. What other type can I use?
>
> When is this example below supposed to work?
>
> // your first date coming from a mysql database (date fields)
> $dateA = '2008-03-01 13:34';
> // your second date coming from a mysql database (date fields)
> $dateB = '2007-04-14 15:23';
> if(strtotime<http://www.php.net/strtotime>($dateA) >
> strtotime<
> http://www.php.net/strtotime>($dateB)){
> // bla bla
> }
>
> Thanks
>
>
> From: Serge Fonville [mailto:serge.fonville@gmail.com]
> Sent: Thursday, January 03, 2013 2:05 PM
> To: Marc Fromm
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] date problem
>
> Hi.
>
> date returns a string
>
> You should compare a different type for bigger/smaller than
>
> HTH
>
> Kind regards/met vriendelijke groet,
>
> Serge Fonville
>
> http://www.sergefonville.nl
>
> Convince Microsoft!
> They need to add TRUNCATE PARTITION in SQL Server
>
>
> https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table
>
> 2013/1/3 Marc Fromm <Marc.Fromm@wwu.edu<�˜r_"²Dcj¥Y
> xmailto:Marc.Fromm@wwu.edu>>
> I am comparing to dates.
>
> define('WSOFFBEGIN','09/16/2012');
> $jes = 01/03/2012;
>
> if ( date("m/d/Y", strtotime($jes)) < date("m/d/Y",
> strtotime(WSOFFBEGIN))
> )
> {
> $error = " MUST begin after " . WSOFFBEGIN . "\n";
> }
>
> I cannot figure out why the $error is being assigned inside the if
> statement, since the statement should be false. 01/03/2012 is not less than
> 09/16/2012.
>
> Marc
>
>