Re: [PHP] date time problem

2013-10-07 Thread Jim Giner

On 10/6/2013 11:21 PM, Romain CIACCAFAVA wrote:

An easier way to do that would be using the diff() method of a DateTime object 
on another.

Regards
Romain Ciaccafava

Romain - you were so right.  A little less calculating to be done and I 
got the result I wished.  For anyone interested here's the function I'm 
using to determine how much time there is until a cookie expires.  The 
cookie in question contains the expiration datetime that was used to 
create a paired cookie.


function GetTimeLeft($applid)
{
   if (isset($_COOKIE[$applid]))
   {
  if (isset($_COOKIE[$applid."expire"]))
  {
 $curr_time = new datetime();
 $cookietime = $_COOKIE[$applid."expire"];
 $exp_time = new datetime();
 $exp_time->setTimeStamp($cookietime);
 $diff = $curr_time->diff($exp_time);
 $days = $diff->format("%d");
 $days = ($days > 1) ? "$days days": ($days == 1) ?
   "$days day" : '';
 $hms = $diff->format("%h:%i:%s");
 return "Time left: $days $hms";
  }
  else
 return '?';
   }
   else
  return '0';
}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Romain CIACCAFAVA
An easier way to do that would be using the diff() method of a DateTime object 
on another.

Regards
Romain Ciaccafava

> Le 7 oct. 2013 à 03:10, Jim Giner  a écrit :
> 
>> On 10/6/2013 7:55 PM, Ashley Sheridan wrote:
>>> On Sun, 2013-10-06 at 19:14 -0400, Aziz Saleh wrote:
>>> 
>>> Jim,
>>> 
>>> The date method takes in a timestamp (not seconds away).
>>> 
>>> You have the seconds, you will need to manually convert those seconds to
>>> what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
>>> 
>>> Aziz
>>> 
>>> 
>>> On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee 
>>> wrote:
>>> 
 Its so freaky
 
 Best Regards
 Farzan Dalaee
 
>> On Oct 7, 2013, at 2:29, Jim Giner  wrote:
>> 
>> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
>> Try this please
>> 
>>  gmdate("H:i:s", $diff%86400)
>> 
>> Best Regards
>> Farzan Dalaee
>> 
 On Oct 7, 2013, at 2:12, Jim Giner 
 wrote:
 
 On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
 You should use  gmdate() if you want to how many hours left to expire
 $time_left = gmdate("H:i:s",$diff);
 
 Best Regards
 Farzan Dalaee
 
> On Oct 7, 2013, at 1:49, Jim Giner 
 wrote:
> 
> I always hate dealing with date/time stuff in php - never get it
 even close until an hour or two goes by
> 
> anyway
> 
> I have this:
> 
> // get two timestamp values
> $exp_time = $_COOKIE[$applid."expire"];
> $curr_time = time();
> // get the difference
> $diff = $exp_time - $curr_time;
> // produce a display time of the diff
> $time_left = date("h:i:s",$diff);
> 
> Currently the results are:
> exp_time is 06:55:07
> curr_time is 06:12:03
> the diff is 2584
> All of these are correct.
> 
> BUT time_left is 07:43:04 when it should be only "00:43:04".
> 
> So - where is the hour value of '07' coming from?? And how do I get
 this right?
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>>> Thanks for the quick response, but why do I want to show the time in
 GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
  Now instead of a 7 for hours I have a 12.
>>> 
>>> exp 07:34:52
>>> curr 06:40:14
>>> diff 3158
>>> left is 12:52:38
>>> 
>>> The 52:38 is the correct value, but not the 12.
>>> 
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
> Doesn't work either.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
>> 
>> Aziz, please try not to top post :)
>> 
>> It's true that the date() function takes in a timestamp as its argument,
>> but a timestamp is a number representing the number of seconds since
>> 00:00:00 1st January 1970, so passing in a very small number of seconds
>> is perfectly valid.
>> 
>> The only thing that would account for the 7 hours difference is the time
>> zone, which would also be part of the timestamp.
>> http://en.wikipedia.org/wiki/Unix_time gives more details.
>> 
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
> Thanks Ash, but the previous (top) post explained my dilemma just as you have 
> done here.  My attempt to use a function to avoid "doing the math" has now 
> been resolved.  Guess I'll have to do it the old-fashioned way.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Jim Giner

On 10/6/2013 7:55 PM, Ashley Sheridan wrote:

On Sun, 2013-10-06 at 19:14 -0400, Aziz Saleh wrote:


Jim,

The date method takes in a timestamp (not seconds away).

You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..

Aziz


On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee wrote:


Its so freaky

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 2:29, Jim Giner  wrote:


On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
Try this please

  gmdate("H:i:s", $diff%86400)

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 2:12, Jim Giner 

wrote:


On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
You should use  gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 1:49, Jim Giner 

wrote:


I always hate dealing with date/time stuff in php - never get it

even close until an hour or two goes by


anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get

this right?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Thanks for the quick response, but why do I want to show the time in

GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
  Now instead of a 7 for hours I have a 12.


exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38

The 52:38 is the correct value, but not the 12.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Doesn't work either.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






Aziz, please try not to top post :)

It's true that the date() function takes in a timestamp as its argument,
but a timestamp is a number representing the number of seconds since
00:00:00 1st January 1970, so passing in a very small number of seconds
is perfectly valid.

The only thing that would account for the 7 hours difference is the time
zone, which would also be part of the timestamp.
http://en.wikipedia.org/wiki/Unix_time gives more details.

Thanks,
Ash
http://www.ashleysheridan.co.uk



Thanks Ash, but the previous (top) post explained my dilemma just as you 
have done here.  My attempt to use a function to avoid "doing the math" 
has now been resolved.  Guess I'll have to do it the old-fashioned way.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Jim Giner

On 10/6/2013 7:40 PM, Aziz Saleh wrote:

The resulting subtraction is not a valid timestamp, but rather the
difference between the two timestamps in seconds . The resulting diff can
be 1 if the timestamps are 1 seconds apart. The
linkJonathan
sent out contains functions that does the division for you with
results. Another link you can check out:

http://stackoverflow.com/a/9143387/1935500



On Sun, Oct 6, 2013 at 7:29 PM, Jim Giner wrote:


Look at my code. The inputs are all timestamps so date should work, no?
My question why am i getting an hour value in this case?

jg


On Oct 6, 2013, at 7:14 PM, Aziz Saleh  wrote:

Jim,

The date method takes in a timestamp (not seconds away).

You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..

Aziz


On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee wrote:


Its so freaky

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 2:29, Jim Giner 

wrote:



On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
Try this please

  gmdate("H:i:s", $diff%86400)

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 2:12, Jim Giner 

wrote:


On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
You should use  gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 1:49, Jim Giner 

wrote:


I always hate dealing with date/time stuff in php - never get it

even close until an hour or two goes by


anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get

this right?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Thanks for the quick response, but why do I want to show the time in

GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
  Now instead of a 7 for hours I have a 12.


exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38

The 52:38 is the correct value, but not the 12.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Doesn't work either.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php








Good Point!  I never looked at it that way.  I guess the Date function 
can't be relied on in that case.  So now I'll have to calculate my time 
in a mathematical way instead of letting Date translate it for me.


Thanks!



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Ashley Sheridan
On Sun, 2013-10-06 at 19:14 -0400, Aziz Saleh wrote:

> Jim,
> 
> The date method takes in a timestamp (not seconds away).
> 
> You have the seconds, you will need to manually convert those seconds to
> what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
> 
> Aziz
> 
> 
> On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee wrote:
> 
> > Its so freaky
> >
> > Best Regards
> > Farzan Dalaee
> >
> > > On Oct 7, 2013, at 2:29, Jim Giner  wrote:
> > >
> > >> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
> > >> Try this please
> > >>
> > >>  gmdate("H:i:s", $diff%86400)
> > >>
> > >> Best Regards
> > >> Farzan Dalaee
> > >>
> >  On Oct 7, 2013, at 2:12, Jim Giner 
> > wrote:
> > 
> >  On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
> >  You should use  gmdate() if you want to how many hours left to expire
> >  $time_left = gmdate("H:i:s",$diff);
> > 
> >  Best Regards
> >  Farzan Dalaee
> > 
> > > On Oct 7, 2013, at 1:49, Jim Giner 
> > wrote:
> > >
> > > I always hate dealing with date/time stuff in php - never get it
> > even close until an hour or two goes by
> > >
> > > anyway
> > >
> > > I have this:
> > >
> > > // get two timestamp values
> > > $exp_time = $_COOKIE[$applid."expire"];
> > > $curr_time = time();
> > > // get the difference
> > > $diff = $exp_time - $curr_time;
> > > // produce a display time of the diff
> > > $time_left = date("h:i:s",$diff);
> > >
> > > Currently the results are:
> > > exp_time is 06:55:07
> > > curr_time is 06:12:03
> > > the diff is 2584
> > > All of these are correct.
> > >
> > > BUT time_left is 07:43:04 when it should be only "00:43:04".
> > >
> > > So - where is the hour value of '07' coming from?? And how do I get
> > this right?
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >>> Thanks for the quick response, but why do I want to show the time in
> > GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
> >  Now instead of a 7 for hours I have a 12.
> > >>>
> > >>> exp 07:34:52
> > >>> curr 06:40:14
> > >>> diff 3158
> > >>> left is 12:52:38
> > >>>
> > >>> The 52:38 is the correct value, but not the 12.
> > >>>
> > >>> --
> > >>> PHP General Mailing List (http://www.php.net/)
> > >>> To unsubscribe, visit: http://www.php.net/unsub.php
> > > Doesn't work either.
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >


Aziz, please try not to top post :)

It's true that the date() function takes in a timestamp as its argument,
but a timestamp is a number representing the number of seconds since
00:00:00 1st January 1970, so passing in a very small number of seconds
is perfectly valid.

The only thing that would account for the 7 hours difference is the time
zone, which would also be part of the timestamp.
http://en.wikipedia.org/wiki/Unix_time gives more details.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] date time problem

2013-10-06 Thread Aziz Saleh
The resulting subtraction is not a valid timestamp, but rather the
difference between the two timestamps in seconds . The resulting diff can
be 1 if the timestamps are 1 seconds apart. The
linkJonathan
sent out contains functions that does the division for you with
results. Another link you can check out:

http://stackoverflow.com/a/9143387/1935500



On Sun, Oct 6, 2013 at 7:29 PM, Jim Giner wrote:

> Look at my code. The inputs are all timestamps so date should work, no?
> My question why am i getting an hour value in this case?
>
> jg
>
>
> On Oct 6, 2013, at 7:14 PM, Aziz Saleh  wrote:
>
> Jim,
>
> The date method takes in a timestamp (not seconds away).
>
> You have the seconds, you will need to manually convert those seconds to
> what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
>
> Aziz
>
>
> On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee wrote:
>
>> Its so freaky
>>
>> Best Regards
>> Farzan Dalaee
>>
>> > On Oct 7, 2013, at 2:29, Jim Giner 
>> wrote:
>> >
>> >> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
>> >> Try this please
>> >>
>> >>  gmdate("H:i:s", $diff%86400)
>> >>
>> >> Best Regards
>> >> Farzan Dalaee
>> >>
>>  On Oct 7, 2013, at 2:12, Jim Giner 
>> wrote:
>> 
>>  On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
>>  You should use  gmdate() if you want to how many hours left to expire
>>  $time_left = gmdate("H:i:s",$diff);
>> 
>>  Best Regards
>>  Farzan Dalaee
>> 
>> > On Oct 7, 2013, at 1:49, Jim Giner 
>> wrote:
>> >
>> > I always hate dealing with date/time stuff in php - never get it
>> even close until an hour or two goes by
>> >
>> > anyway
>> >
>> > I have this:
>> >
>> > // get two timestamp values
>> > $exp_time = $_COOKIE[$applid."expire"];
>> > $curr_time = time();
>> > // get the difference
>> > $diff = $exp_time - $curr_time;
>> > // produce a display time of the diff
>> > $time_left = date("h:i:s",$diff);
>> >
>> > Currently the results are:
>> > exp_time is 06:55:07
>> > curr_time is 06:12:03
>> > the diff is 2584
>> > All of these are correct.
>> >
>> > BUT time_left is 07:43:04 when it should be only "00:43:04".
>> >
>> > So - where is the hour value of '07' coming from?? And how do I get
>> this right?
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >>> Thanks for the quick response, but why do I want to show the time in
>> GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
>>  Now instead of a 7 for hours I have a 12.
>> >>>
>> >>> exp 07:34:52
>> >>> curr 06:40:14
>> >>> diff 3158
>> >>> left is 12:52:38
>> >>>
>> >>> The 52:38 is the correct value, but not the 12.
>> >>>
>> >>> --
>> >>> PHP General Mailing List (http://www.php.net/)
>> >>> To unsubscribe, visit: http://www.php.net/unsub.php
>> > Doesn't work either.
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>>
>
>


Re: [PHP] date time problem

2013-10-06 Thread Jim Giner
Look at my code. The inputs are all timestamps so date should work, no?
My question why am i getting an hour value in this case?

jg


On Oct 6, 2013, at 7:14 PM, Aziz Saleh  wrote:

> Jim,
> 
> The date method takes in a timestamp (not seconds away).
> 
> You have the seconds, you will need to manually convert those seconds to what 
> you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
> 
> Aziz
> 
> 
> On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee  wrote:
>> Its so freaky
>> 
>> Best Regards
>> Farzan Dalaee
>> 
>> > On Oct 7, 2013, at 2:29, Jim Giner  wrote:
>> >
>> >> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
>> >> Try this please
>> >>
>> >>  gmdate("H:i:s", $diff%86400)
>> >>
>> >> Best Regards
>> >> Farzan Dalaee
>> >>
>>  On Oct 7, 2013, at 2:12, Jim Giner  wrote:
>> 
>>  On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
>>  You should use  gmdate() if you want to how many hours left to expire
>>  $time_left = gmdate("H:i:s",$diff);
>> 
>>  Best Regards
>>  Farzan Dalaee
>> 
>> > On Oct 7, 2013, at 1:49, Jim Giner  
>> > wrote:
>> >
>> > I always hate dealing with date/time stuff in php - never get it even 
>> > close until an hour or two goes by
>> >
>> > anyway
>> >
>> > I have this:
>> >
>> > // get two timestamp values
>> > $exp_time = $_COOKIE[$applid."expire"];
>> > $curr_time = time();
>> > // get the difference
>> > $diff = $exp_time - $curr_time;
>> > // produce a display time of the diff
>> > $time_left = date("h:i:s",$diff);
>> >
>> > Currently the results are:
>> > exp_time is 06:55:07
>> > curr_time is 06:12:03
>> > the diff is 2584
>> > All of these are correct.
>> >
>> > BUT time_left is 07:43:04 when it should be only "00:43:04".
>> >
>> > So - where is the hour value of '07' coming from?? And how do I get 
>> > this right?
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >>> Thanks for the quick response, but why do I want to show the time in 
>> >>> GMT?  However, I did try it, changing the 'time_left' calc to use 
>> >>> "gmdate".  Now instead of a 7 for hours I have a 12.
>> >>>
>> >>> exp 07:34:52
>> >>> curr 06:40:14
>> >>> diff 3158
>> >>> left is 12:52:38
>> >>>
>> >>> The 52:38 is the correct value, but not the 12.
>> >>>
>> >>> --
>> >>> PHP General Mailing List (http://www.php.net/)
>> >>> To unsubscribe, visit: http://www.php.net/unsub.php
>> > Doesn't work either.
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
> 


Re: [PHP] date time problem

2013-10-06 Thread Aziz Saleh
Jim,

The date method takes in a timestamp (not seconds away).

You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..

Aziz


On Sun, Oct 6, 2013 at 7:07 PM, Farzan Dalaee wrote:

> Its so freaky
>
> Best Regards
> Farzan Dalaee
>
> > On Oct 7, 2013, at 2:29, Jim Giner  wrote:
> >
> >> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
> >> Try this please
> >>
> >>  gmdate("H:i:s", $diff%86400)
> >>
> >> Best Regards
> >> Farzan Dalaee
> >>
>  On Oct 7, 2013, at 2:12, Jim Giner 
> wrote:
> 
>  On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
>  You should use  gmdate() if you want to how many hours left to expire
>  $time_left = gmdate("H:i:s",$diff);
> 
>  Best Regards
>  Farzan Dalaee
> 
> > On Oct 7, 2013, at 1:49, Jim Giner 
> wrote:
> >
> > I always hate dealing with date/time stuff in php - never get it
> even close until an hour or two goes by
> >
> > anyway
> >
> > I have this:
> >
> > // get two timestamp values
> > $exp_time = $_COOKIE[$applid."expire"];
> > $curr_time = time();
> > // get the difference
> > $diff = $exp_time - $curr_time;
> > // produce a display time of the diff
> > $time_left = date("h:i:s",$diff);
> >
> > Currently the results are:
> > exp_time is 06:55:07
> > curr_time is 06:12:03
> > the diff is 2584
> > All of these are correct.
> >
> > BUT time_left is 07:43:04 when it should be only "00:43:04".
> >
> > So - where is the hour value of '07' coming from?? And how do I get
> this right?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >>> Thanks for the quick response, but why do I want to show the time in
> GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
>  Now instead of a 7 for hours I have a 12.
> >>>
> >>> exp 07:34:52
> >>> curr 06:40:14
> >>> diff 3158
> >>> left is 12:52:38
> >>>
> >>> The 52:38 is the correct value, but not the 12.
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> > Doesn't work either.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


Re: [PHP] date time problem

2013-10-06 Thread Jonathan Sundquist
This should help you out
http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php
On Oct 6, 2013 6:07 PM, "Farzan Dalaee"  wrote:

> Its so freaky
>
> Best Regards
> Farzan Dalaee
>
> > On Oct 7, 2013, at 2:29, Jim Giner  wrote:
> >
> >> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
> >> Try this please
> >>
> >>  gmdate("H:i:s", $diff%86400)
> >>
> >> Best Regards
> >> Farzan Dalaee
> >>
>  On Oct 7, 2013, at 2:12, Jim Giner 
> wrote:
> 
>  On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
>  You should use  gmdate() if you want to how many hours left to expire
>  $time_left = gmdate("H:i:s",$diff);
> 
>  Best Regards
>  Farzan Dalaee
> 
> > On Oct 7, 2013, at 1:49, Jim Giner 
> wrote:
> >
> > I always hate dealing with date/time stuff in php - never get it
> even close until an hour or two goes by
> >
> > anyway
> >
> > I have this:
> >
> > // get two timestamp values
> > $exp_time = $_COOKIE[$applid."expire"];
> > $curr_time = time();
> > // get the difference
> > $diff = $exp_time - $curr_time;
> > // produce a display time of the diff
> > $time_left = date("h:i:s",$diff);
> >
> > Currently the results are:
> > exp_time is 06:55:07
> > curr_time is 06:12:03
> > the diff is 2584
> > All of these are correct.
> >
> > BUT time_left is 07:43:04 when it should be only "00:43:04".
> >
> > So - where is the hour value of '07' coming from?? And how do I get
> this right?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >>> Thanks for the quick response, but why do I want to show the time in
> GMT?  However, I did try it, changing the 'time_left' calc to use "gmdate".
>  Now instead of a 7 for hours I have a 12.
> >>>
> >>> exp 07:34:52
> >>> curr 06:40:14
> >>> diff 3158
> >>> left is 12:52:38
> >>>
> >>> The 52:38 is the correct value, but not the 12.
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> > Doesn't work either.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


Re: [PHP] date time problem

2013-10-06 Thread Farzan Dalaee
Its so freaky 

Best Regards
Farzan Dalaee

> On Oct 7, 2013, at 2:29, Jim Giner  wrote:
> 
>> On 10/6/2013 6:49 PM, Farzan Dalaee wrote:
>> Try this please
>> 
>>  gmdate("H:i:s", $diff%86400)
>> 
>> Best Regards
>> Farzan Dalaee
>> 
 On Oct 7, 2013, at 2:12, Jim Giner  wrote:
 
 On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
 You should use  gmdate() if you want to how many hours left to expire
 $time_left = gmdate("H:i:s",$diff);
 
 Best Regards
 Farzan Dalaee
 
> On Oct 7, 2013, at 1:49, Jim Giner  wrote:
> 
> I always hate dealing with date/time stuff in php - never get it even 
> close until an hour or two goes by
> 
> anyway
> 
> I have this:
> 
> // get two timestamp values
> $exp_time = $_COOKIE[$applid."expire"];
> $curr_time = time();
> // get the difference
> $diff = $exp_time - $curr_time;
> // produce a display time of the diff
> $time_left = date("h:i:s",$diff);
> 
> Currently the results are:
> exp_time is 06:55:07
> curr_time is 06:12:03
> the diff is 2584
> All of these are correct.
> 
> BUT time_left is 07:43:04 when it should be only "00:43:04".
> 
> So - where is the hour value of '07' coming from?? And how do I get this 
> right?
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>>> Thanks for the quick response, but why do I want to show the time in GMT?  
>>> However, I did try it, changing the 'time_left' calc to use "gmdate".  Now 
>>> instead of a 7 for hours I have a 12.
>>> 
>>> exp 07:34:52
>>> curr 06:40:14
>>> diff 3158
>>> left is 12:52:38
>>> 
>>> The 52:38 is the correct value, but not the 12.
>>> 
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
> Doesn't work either.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


Re: [PHP] date time problem

2013-10-06 Thread Jim Giner

On 10/6/2013 6:49 PM, Farzan Dalaee wrote:

Try this please

  gmdate("H:i:s", $diff%86400)

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 2:12, Jim Giner  wrote:


On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
You should use  gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 1:49, Jim Giner  wrote:

I always hate dealing with date/time stuff in php - never get it even close 
until an hour or two goes by

anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get this right?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Thanks for the quick response, but why do I want to show the time in GMT?  However, I did 
try it, changing the 'time_left' calc to use "gmdate".  Now instead of a 7 for 
hours I have a 12.

exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38

The 52:38 is the correct value, but not the 12.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Doesn't work either.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Farzan Dalaee
Try this please

 gmdate("H:i:s", $diff%86400) 

Best Regards
Farzan Dalaee

> On Oct 7, 2013, at 2:12, Jim Giner  wrote:
> 
>> On 10/6/2013 6:36 PM, Farzan Dalaee wrote:
>> You should use  gmdate() if you want to how many hours left to expire
>> $time_left = gmdate("H:i:s",$diff);
>> 
>> Best Regards
>> Farzan Dalaee
>> 
>>> On Oct 7, 2013, at 1:49, Jim Giner  wrote:
>>> 
>>> I always hate dealing with date/time stuff in php - never get it even close 
>>> until an hour or two goes by
>>> 
>>> anyway
>>> 
>>> I have this:
>>> 
>>> // get two timestamp values
>>> $exp_time = $_COOKIE[$applid."expire"];
>>> $curr_time = time();
>>> // get the difference
>>> $diff = $exp_time - $curr_time;
>>> // produce a display time of the diff
>>> $time_left = date("h:i:s",$diff);
>>> 
>>> Currently the results are:
>>> exp_time is 06:55:07
>>> curr_time is 06:12:03
>>> the diff is 2584
>>> All of these are correct.
>>> 
>>> BUT time_left is 07:43:04 when it should be only "00:43:04".
>>> 
>>> So - where is the hour value of '07' coming from?? And how do I get this 
>>> right?
>>> 
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
> Thanks for the quick response, but why do I want to show the time in GMT?  
> However, I did try it, changing the 'time_left' calc to use "gmdate".  Now 
> instead of a 7 for hours I have a 12.
> 
> exp 07:34:52
> curr 06:40:14
> diff 3158
> left is 12:52:38
> 
> The 52:38 is the correct value, but not the 12.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


Re: [PHP] date time problem

2013-10-06 Thread Jim Giner

On 10/6/2013 6:36 PM, Farzan Dalaee wrote:

You should use  gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee


On Oct 7, 2013, at 1:49, Jim Giner  wrote:

I always hate dealing with date/time stuff in php - never get it even close 
until an hour or two goes by

anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get this right?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Thanks for the quick response, but why do I want to show the time in 
GMT?  However, I did try it, changing the 'time_left' calc to use 
"gmdate".  Now instead of a 7 for hours I have a 12.


exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38

The 52:38 is the correct value, but not the 12.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date time problem

2013-10-06 Thread Farzan Dalaee
You should use  gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee

> On Oct 7, 2013, at 1:49, Jim Giner  wrote:
> 
> I always hate dealing with date/time stuff in php - never get it even close 
> until an hour or two goes by
> 
> anyway
> 
> I have this:
> 
> // get two timestamp values
> $exp_time = $_COOKIE[$applid."expire"];
> $curr_time = time();
> // get the difference
> $diff = $exp_time - $curr_time;
> // produce a display time of the diff
> $time_left = date("h:i:s",$diff);
> 
> Currently the results are:
> exp_time is 06:55:07
> curr_time is 06:12:03
> the diff is 2584
> All of these are correct.
> 
> BUT time_left is 07:43:04 when it should be only "00:43:04".
> 
> So - where is the hour value of '07' coming from?? And how do I get this 
> right?
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


[PHP] date time problem

2013-10-06 Thread Jim Giner
I always hate dealing with date/time stuff in php - never get it even 
close until an hour or two goes by


anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get this 
right?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date weirdness

2013-04-18 Thread Larry Martell
On Thu, Mar 28, 2013 at 3:40 PM, Larry Martell  wrote:
> On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples  wrote:
>>> I think I am losing my mind. I have some time zone converting code, and I
>>> just don't understand what I am seeing. Also my system seems to return the
>>> wrong time after I do some date operations on unrelated objects.
>>>
>>> This is from a machine that is in eastern time. I want to convert to, for
>>> example central time:
>>>
>>> $ndate = new Date(date("Y-m-d H:i:s"));
>>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>>> 2013-03-28 15:35:07  <- this is the correct time
>>>
>>> $ndate->setTZbyID("EDT");
>>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>>> 2013-03-28 15:35:07 <- still correct
>>>
>>> $ndate->convertTZbyID("US/Central");
>>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>>> 2013-03-28 10:35:07 <- this is wrong it should be 14:35:07
>>>
>>> $xdate = new Date(date("Y-m-d H:i:s"));
>>> echo $xdate->format("%Y-%m-%d %H:%M:%S");
>>> 2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07
>>>
>>> What in the world is going on here?
>>>
>>
>> I found this function a while back when I was converting UTC to EST... 
>> simple task I know, but still...
>>
>> ( I am sorry to whomever wrote this, I didn't keep the source where I found 
>> it )
>>
>> function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
>> 'America/Toronto')
>> {
>> $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
>> $time_object->setTimezone(new DateTimeZone($to_tz));
>> return $time_object->format('Y-m-d H:i:s');
>> }
>
> I don't seem to have the DateTime object. We are running 5.1.6 and
> that was added in 5.2.0. We are getting the Date module from an
> external extension. I'll have to see about upgrading.

I've upgraded to 5.3.3, got rid of the external Date extension and
implement your solution. It's working perfectly. Thanks much!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date weirdness

2013-03-28 Thread Larry Martell
On Thu, Mar 28, 2013 at 4:55 PM, Maciek Sokolewicz
 wrote:
> On 28-3-2013 22:40, Larry Martell wrote:
>>
>> On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples  wrote:

 I think I am losing my mind. I have some time zone converting code, and
 I
 just don't understand what I am seeing. Also my system seems to return
 the
 wrong time after I do some date operations on unrelated objects.

 This is from a machine that is in eastern time. I want to convert to,
 for
 example central time:

 $ndate = new Date(date("Y-m-d H:i:s"));
 echo $ndate->format("%Y-%m-%d %H:%M:%S");
 2013-03-28 15:35:07  <- this is the correct time

 $ndate->setTZbyID("EDT");
 echo $ndate->format("%Y-%m-%d %H:%M:%S");
 2013-03-28 15:35:07 <- still correct

 $ndate->convertTZbyID("US/Central");
 echo $ndate->format("%Y-%m-%d %H:%M:%S");
 2013-03-28 10:35:07 <- this is wrong it should be 14:35:07

 $xdate = new Date(date("Y-m-d H:i:s"));
 echo $xdate->format("%Y-%m-%d %H:%M:%S");
 2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07

 What in the world is going on here?

>>>
>>> I found this function a while back when I was converting UTC to EST...
>>> simple task I know, but still...
>>>
>>> ( I am sorry to whomever wrote this, I didn't keep the source where I
>>> found it )
>>>
>>> function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz =
>>> 'America/Toronto')
>>> {
>>>  $time_object = new DateTime($date_time, new
>>> DateTimeZone($from_tz));
>>>  $time_object->setTimezone(new DateTimeZone($to_tz));
>>>  return $time_object->format('Y-m-d H:i:s');
>>> }
>>
>>
>> I don't seem to have the DateTime object. We are running 5.1.6 and
>> that was added in 5.2.0. We are getting the Date module from an
>> external extension. I'll have to see about upgrading.
>>
> Well, if you're getting the Date class from a custom extension, then we
> can't help you. Simply because we have no clue what the extension's code is.
>
> Also, please ask your host to upgrade, 5.1.6 is hopelessly outdated (and
> unsupported!). The current version is 5.4 with 5.5 coming out very very
> soon.
>

The extension is this:
http://pear.php.net/package/Date/docs/latest/Date/Date.html - but that
is also a very old version. I am working on getting the upgrade done.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date weirdness

2013-03-28 Thread Maciek Sokolewicz

On 28-3-2013 22:40, Larry Martell wrote:

On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples  wrote:

I think I am losing my mind. I have some time zone converting code, and I
just don't understand what I am seeing. Also my system seems to return the
wrong time after I do some date operations on unrelated objects.

This is from a machine that is in eastern time. I want to convert to, for
example central time:

$ndate = new Date(date("Y-m-d H:i:s"));
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 15:35:07  <- this is the correct time

$ndate->setTZbyID("EDT");
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 15:35:07 <- still correct

$ndate->convertTZbyID("US/Central");
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 10:35:07 <- this is wrong it should be 14:35:07

$xdate = new Date(date("Y-m-d H:i:s"));
echo $xdate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07

What in the world is going on here?



I found this function a while back when I was converting UTC to EST... simple 
task I know, but still...

( I am sorry to whomever wrote this, I didn't keep the source where I found it )

function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
'America/Toronto')
{
 $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
 $time_object->setTimezone(new DateTimeZone($to_tz));
 return $time_object->format('Y-m-d H:i:s');
}


I don't seem to have the DateTime object. We are running 5.1.6 and
that was added in 5.2.0. We are getting the Date module from an
external extension. I'll have to see about upgrading.

Well, if you're getting the Date class from a custom extension, then we 
can't help you. Simply because we have no clue what the extension's code 
is.


Also, please ask your host to upgrade, 5.1.6 is hopelessly outdated (and 
unsupported!). The current version is 5.4 with 5.5 coming out very very 
soon.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date weirdness

2013-03-28 Thread Larry Martell
On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples  wrote:
>> I think I am losing my mind. I have some time zone converting code, and I
>> just don't understand what I am seeing. Also my system seems to return the
>> wrong time after I do some date operations on unrelated objects.
>>
>> This is from a machine that is in eastern time. I want to convert to, for
>> example central time:
>>
>> $ndate = new Date(date("Y-m-d H:i:s"));
>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>> 2013-03-28 15:35:07  <- this is the correct time
>>
>> $ndate->setTZbyID("EDT");
>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>> 2013-03-28 15:35:07 <- still correct
>>
>> $ndate->convertTZbyID("US/Central");
>> echo $ndate->format("%Y-%m-%d %H:%M:%S");
>> 2013-03-28 10:35:07 <- this is wrong it should be 14:35:07
>>
>> $xdate = new Date(date("Y-m-d H:i:s"));
>> echo $xdate->format("%Y-%m-%d %H:%M:%S");
>> 2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07
>>
>> What in the world is going on here?
>>
>
> I found this function a while back when I was converting UTC to EST... simple 
> task I know, but still...
>
> ( I am sorry to whomever wrote this, I didn't keep the source where I found 
> it )
>
> function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
> 'America/Toronto')
> {
> $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
> $time_object->setTimezone(new DateTimeZone($to_tz));
> return $time_object->format('Y-m-d H:i:s');
> }

I don't seem to have the DateTime object. We are running 5.1.6 and
that was added in 5.2.0. We are getting the Date module from an
external extension. I'll have to see about upgrading.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date weirdness

2013-03-28 Thread Steven Staples
> I think I am losing my mind. I have some time zone converting code, and I
> just don't understand what I am seeing. Also my system seems to return the
> wrong time after I do some date operations on unrelated objects.
> 
> This is from a machine that is in eastern time. I want to convert to, for
> example central time:
> 
> $ndate = new Date(date("Y-m-d H:i:s"));
> echo $ndate->format("%Y-%m-%d %H:%M:%S");
> 2013-03-28 15:35:07  <- this is the correct time
> 
> $ndate->setTZbyID("EDT");
> echo $ndate->format("%Y-%m-%d %H:%M:%S");
> 2013-03-28 15:35:07 <- still correct
> 
> $ndate->convertTZbyID("US/Central");
> echo $ndate->format("%Y-%m-%d %H:%M:%S");
> 2013-03-28 10:35:07 <- this is wrong it should be 14:35:07
> 
> $xdate = new Date(date("Y-m-d H:i:s"));
> echo $xdate->format("%Y-%m-%d %H:%M:%S");
> 2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07
> 
> What in the world is going on here?
> 

I found this function a while back when I was converting UTC to EST... simple 
task I know, but still...

( I am sorry to whomever wrote this, I didn't keep the source where I found it )

function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
'America/Toronto')
{
$time_object = new DateTime($date_time, new DateTimeZone($from_tz));
$time_object->setTimezone(new DateTimeZone($to_tz));
return $time_object->format('Y-m-d H:i:s');
}

Maybe this can help you?

Steve 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Date weirdness

2013-03-28 Thread Larry Martell
I think I am losing my mind. I have some time zone converting code,
and I just don't understand what I am seeing. Also my system seems to
return the wrong time after I do some date operations on unrelated
objects.

This is from a machine that is in eastern time. I want to convert to,
for example central time:


$ndate = new Date(date("Y-m-d H:i:s"));
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 15:35:07  <- this is the correct time

$ndate->setTZbyID("EDT");
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 15:35:07 <- still correct

$ndate->convertTZbyID("US/Central");
echo $ndate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 10:35:07 <- this is wrong it should be 14:35:07

$xdate = new Date(date("Y-m-d H:i:s"));
echo $xdate->format("%Y-%m-%d %H:%M:%S");
2013-03-28 19:35:07 <- HUH? This is wrong - should be 15:35:07

What in the world is going on here?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2013-01-03 Thread Jim Lucas

On 01/03/2013 01:57 PM, Marc Fromm wrote:

$jes = 01/03/2012;


# php -r "echo 01/03/2012;"
0.00016567263088138

You might want to put quotes around that value so it is actually a 
string and does not get evaluated.


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2013-01-03 Thread Jim Giner

On 1/3/2013 5:22 PM, Marc Fromm wrote:

Thanks Jonathan. I removed the date() syntax function and it works.

From: Jonathan Sundquist [mailto:jsundqu...@gmail.com]
Sent: Thursday, January 03, 2013 2:16 PM
To: Marc Fromm
Cc: Serge Fonville; php-general@lists.php.net
Subject: Re: [PHP] date problem

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 
mailto:marc.fr...@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.fonvi...@gmail.com<mailto:serge.fonvi...@gmail.com>]
Sent: Thursday, January 03, 2013 2:05 PM
To: Marc Fromm
Cc: php-general@lists.php.net<mailto: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 
mailto:marc.fr...@wwu.edu><mailto:marc.fr...@wwu.edu<mailto:marc.fr...@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



And hopefully put quotes around 01/03/2012.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] date problem

2013-01-03 Thread Marc Fromm
Thanks Jonathan. I removed the date() syntax function and it works.

From: Jonathan Sundquist [mailto:jsundqu...@gmail.com]
Sent: Thursday, January 03, 2013 2:16 PM
To: Marc Fromm
Cc: Serge Fonville; php-general@lists.php.net
Subject: Re: [PHP] date problem

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 
mailto:marc.fr...@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.fonvi...@gmail.com<mailto:serge.fonvi...@gmail.com>]
Sent: Thursday, January 03, 2013 2:05 PM
To: Marc Fromm
Cc: php-general@lists.php.net<mailto: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 
mailto:marc.fr...@wwu.edu><mailto:marc.fr...@wwu.edu<mailto:marc.fr...@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



Re: [PHP] date problem

2013-01-03 Thread Jonathan Sundquist
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  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.fonvi...@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 mailto:marc.fr...@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
>
>


RE: [PHP] date problem

2013-01-03 Thread Marc Fromm
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.fonvi...@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 mailto:marc.fr...@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



Re: [PHP] date problem

2013-01-03 Thread Ken Robinson

At 04:57 PM 1/3/2013, Marc Fromm wrote:

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.


You shouldn't be comparing the date strings, but the UNIX timestamp values:

define('WSOFFBEGIN','09/16/2012');
$jes = 01/03/2012;

if ( strtotime($jes) < strtotime(WSOFFBEGIN) )
{
$error = " MUST begin after " . WSOFFBEGIN . "\n";
}

Ken



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2013-01-03 Thread Serge Fonville
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 

> 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
>


Re: [PHP] date problem

2013-01-03 Thread Jonathan Sundquist
1/3/2012 is in fact less then 9/16/2012.


On Thu, Jan 3, 2013 at 3:57 PM, Marc Fromm  wrote:

> 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
>


[PHP] date problem

2013-01-03 Thread Marc Fromm
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


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-20 Thread Terry Ally (Gmail)
It's a nice shortcut Jim. Never considered that.

Thanks.

On 20 November 2012 21:03, Jim Lucas  wrote:

> On 11/12/2012 02:06 AM, Duken Marga wrote:
>
>> Try this:
>>
>> $todaydate = strtotime(date("D, M jS, Y g:i:s a"));
>> $showenddate = strtotime(date("D, M jS, Y g:i:s a",
>> strtotime($showsRecord['end_**date'])));
>>
>
> Won't this give you the same results without the extra conversion steps?
>
> $todaydate = date("U");
>
> $showenddate = strtotime($showsRecord['end_**date']);
>
>
>> if ($todaydate<  $showenddate):
>>  echo "The date of the show has not yet arrived";
>> else:
>>  echo "The show has ended";
>> endif;
>>
>> You must convert both $todaydate and $showendate with strtotime()
>> function,
>> then you can compare them.
>>
>> On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail)*
>> *wrote:
>>
>>  Hi all,
>>>
>>> I am having a problem with comparing time. I am using the following:
>>>
>>> $todaydate = date("D, M jS, Y g:i:s a");
>>> $showenddate = date("D, M jS, Y g:i:s a",
>>> strtotime($showsRecord['end_**date']));
>>>
>>> if ($todaydate>  $showenddate):
>>>  echo "The date of the show has not yet arrived";
>>> else:
>>>  echo "The show has ended";
>>> endif;
>>>
>>> The problem that I am encountering is that PHP is rendering the reverse
>>> of
>>> the equation. For example:
>>>
>>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov
>>> 2012*,
>>> the message that I am getting is *the show has ended* which is wrong. A
>>> test example is at 
>>> http://www.lakesidesurrey.co.**uk/test.php
>>> .
>>>
>>> You can also me what I am doing wrong?
>>>
>>> Thanks
>>> Terry
>>>
>>>
>>
>>
>>
>
> --
> Jim Lucas
>
> http://www.cmsws.com/
> http://www.cmsws.com/examples/
>



-- 
*Terry Ally*
Twitter.com/terryally
Facebook.com/terryally
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
To print or not to print this email is the environmentally-searching
question!
Which has the highest ecological cost? A sheet of paper or constantly
switching on your computer and connecting to the Internet to read your
email?


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-20 Thread Jim Lucas

On 11/12/2012 02:06 AM, Duken Marga wrote:

Try this:

$todaydate = strtotime(date("D, M jS, Y g:i:s a"));
$showenddate = strtotime(date("D, M jS, Y g:i:s a",
strtotime($showsRecord['end_date'])));


Won't this give you the same results without the extra conversion steps?

$todaydate = date("U");
$showenddate = strtotime($showsRecord['end_date']);



if ($todaydate<  $showenddate):
 echo "The date of the show has not yet arrived";
else:
 echo "The show has ended";
endif;

You must convert both $todaydate and $showendate with strtotime() function,
then you can compare them.

On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail)wrote:


Hi all,

I am having a problem with comparing time. I am using the following:

$todaydate = date("D, M jS, Y g:i:s a");
$showenddate = date("D, M jS, Y g:i:s a",
strtotime($showsRecord['end_date']));

if ($todaydate>  $showenddate):
 echo "The date of the show has not yet arrived";
else:
 echo "The show has ended";
endif;

The problem that I am encountering is that PHP is rendering the reverse of
the equation. For example:

If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
the message that I am getting is *the show has ended* which is wrong. A
test example is at http://www.lakesidesurrey.co.uk/test.php.

You can also me what I am doing wrong?

Thanks
Terry








--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-20 Thread Terry Ally (Gmail)
Dear Duken,

Many thanks for the solution. It worked!

And thanks to everyone else who pitched in with various solutions.

Regards
Terry

On 12 November 2012 10:06, Duken Marga  wrote:

> Try this:
>
> $todaydate = strtotime(date("D, M jS, Y g:i:s a"));
> $showenddate = strtotime(date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date'])));
>
>
> if ($todaydate < $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> You must convert both $todaydate and $showendate with strtotime()
> function, then you can compare them.
>
> On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail) 
> wrote:
>
>> Hi all,
>>
>> I am having a problem with comparing time. I am using the following:
>>
>> $todaydate = date("D, M jS, Y g:i:s a");
>> $showenddate = date("D, M jS, Y g:i:s a",
>> strtotime($showsRecord['end_date']));
>>
>> if ($todaydate > $showenddate):
>> echo "The date of the show has not yet arrived";
>> else:
>> echo "The show has ended";
>> endif;
>>
>> The problem that I am encountering is that PHP is rendering the reverse of
>> the equation. For example:
>>
>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
>> the message that I am getting is *the show has ended* which is wrong. A
>>
>> test example is at http://www.lakesidesurrey.co.uk/test.php.
>>
>> You can also me what I am doing wrong?
>>
>> Thanks
>> Terry
>>
>
>
>
> --
> Duken Marga
>
>
>


-- 
*Terry Ally*
Twitter.com/terryally
Facebook.com/terryally
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
To print or not to print this email is the environmentally-searching
question!
Which has the highest ecological cost? A sheet of paper or constantly
switching on your computer and connecting to the Internet to read your
email?


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-13 Thread Matijn Woudt
On Tue, Nov 13, 2012 at 5:11 AM, Kanishka  wrote:

> if we use a date after 19 January 2038, we can not use 'strtotime' to get
> timestamp.
> http://en.wikipedia.org/wiki/Year_2038_problem
>
>
Only if you're running 32bit OS. If you're running 64bit OS with 64bit PHP
you can represent about 580 billion years...

- Matijn


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-12 Thread Kanishka
if we use a date after 19 January 2038, we can not use 'strtotime' to get
timestamp.
http://en.wikipedia.org/wiki/Year_2038_problem


On Mon, Nov 12, 2012 at 3:36 PM, Duken Marga  wrote:

> Try this:
>
> $todaydate = strtotime(date("D, M jS, Y g:i:s a"));
> $showenddate = strtotime(date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date'])));
>
> if ($todaydate < $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> You must convert both $todaydate and $showendate with strtotime() function,
> then you can compare them.
>
> On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail)  >wrote:
>
> > Hi all,
> >
> > I am having a problem with comparing time. I am using the following:
> >
> > $todaydate = date("D, M jS, Y g:i:s a");
> > $showenddate = date("D, M jS, Y g:i:s a",
> > strtotime($showsRecord['end_date']));
> >
> > if ($todaydate > $showenddate):
> > echo "The date of the show has not yet arrived";
> > else:
> > echo "The show has ended";
> > endif;
> >
> > The problem that I am encountering is that PHP is rendering the reverse
> of
> > the equation. For example:
> >
> > If today's date is *11 Nov 2012* and the show's end date is *18 Nov
> 2012*,
> > the message that I am getting is *the show has ended* which is wrong. A
> > test example is at http://www.lakesidesurrey.co.uk/test.php.
> >
> > You can also me what I am doing wrong?
> >
> > Thanks
> > Terry
> >
>
>
>
> --
> Duken Marga
>


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-12 Thread Duken Marga
Try this:

$todaydate = strtotime(date("D, M jS, Y g:i:s a"));
$showenddate = strtotime(date("D, M jS, Y g:i:s a",
strtotime($showsRecord['end_date'])));

if ($todaydate < $showenddate):
echo "The date of the show has not yet arrived";
else:
echo "The show has ended";
endif;

You must convert both $todaydate and $showendate with strtotime() function,
then you can compare them.

On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail) wrote:

> Hi all,
>
> I am having a problem with comparing time. I am using the following:
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
>
> if ($todaydate > $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
>
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
>
> You can also me what I am doing wrong?
>
> Thanks
> Terry
>



-- 
Duken Marga


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-12 Thread ma...@behnke.biz


"Terry Ally (Gmail)"  hat am 11. November 2012 um 19:30
geschrieben:
> Hi all,
>
> I am having a problem with comparing time. I am using the following:
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
>
> if ($todaydate > $showenddate):

Read about http://de1.php.net/manual/en/datetime.diff.php


> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
>
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
>
> You can also me what I am doing wrong?
>
> Thanks
> Terry

--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Stuart Dallas
On 11 Nov 2012, at 19:24, "Terry Ally (Gmail)"  wrote:

> I reversed it as you suggested and every future show is displaying as having 
> ended.

In that case the code you're showing us is not the code you're running, because 
that's the obvious error in test.php.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

> On 11 November 2012 19:11, Stuart Dallas  wrote:
> Please include the list when replying.
> 
> On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)"  wrote:
> 
> > What I want is the reverse.
> >
> > I want that if people attempt to access the show page after the show has 
> > ended that it triggers an error which takes it to another page. The actual 
> > conditional statement is as follows (which I will replace with timestamp):
> >
> >   $todaydate = date("D, M jS, Y g:i:s a");
> >   $showenddate = date("D, M jS, Y g:i:s a", 
> > strtotime($showsRecord['end_date']));
> > if ($todaydate > $showenddate) {
> >   header( 'Location: eventdetails_error.php' ) ;
> >   }
> 
> This is what you have:
> 
> if ($todaydate > $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
> 
> That says: if the current time is later than the end date of the show, tell 
> them the date of the show hasn't arrived yet.
> 
> What you mean is: if the current time is later than the end of the show, tell 
> them the show has ended.
> 
> if ($todaydate < $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
> 
> It's a simple logic error.
> 
> -Stuart
> 
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
> 
> > On 11 November 2012 19:04, Stuart Dallas  wrote:
> > On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)"  wrote:
> >
> > > Hi Shiplu and Stuart,
> > >
> > > Comparing timestamps was my first option. I've reinstated it. Have a look
> > > at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you
> > > will see that PHP is still outputting the wrong thing.
> > >
> > > I just can't figure out what's wrong.
> >
> > Your comparison is backwards:
> >
> > if ($todaydate > $showenddate):
> >
> > should be
> >
> > if ($todaydate < $showenddate):
> >
> > -Stuart
> >
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
> >
> > > On 11 November 2012 18:48, shiplu  wrote:
> > >
> > >> You can always use timestamp which is integer.
> > >>
> > >> $todaydate = time();
> > >> $showenddate = strtotime($showsRecord['end_date']);
> > >>
> > >>
> > >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) 
> > >> wrote:
> > >>
> > >>> Hi all,
> > >>>
> > >>> I am having a problem with comparing time. I am using the following:
> > >>>
> > >>> $todaydate = date("D, M jS, Y g:i:s a");
> > >>> $showenddate = date("D, M jS, Y g:i:s a",
> > >>> strtotime($showsRecord['end_date']));
> > >>>
> > >>> if ($todaydate > $showenddate):
> > >>>echo "The date of the show has not yet arrived";
> > >>> else:
> > >>>echo "The show has ended";
> > >>> endif;
> > >>>
> > >>> The problem that I am encountering is that PHP is rendering the reverse 
> > >>> of
> > >>> the equation. For example:
> > >>>
> > >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 
> > >>> 2012*,
> > >>> the message that I am getting is *the show has ended* which is wrong. A
> > >>>
> > >>> test example is at http://www.lakesidesurrey.co.uk/test.php.
> > >>>
> > >>> You can also me what I am doing wrong?
> > >>>
> > >>> Thanks
> > >>> Terry
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Shiplu.Mokadd.im
> > >> ImgSign.com | A dynamic signature machine
> > >> Innovation distinguishes between follower and leader
> > >>
> > >>
> > >
> > >
> > > --
> > > *Terry Ally*
> > > Twitter.com/terryally
> > > Facebook.com/terryally
> > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > > To print or not to print this email is the environmentally-searching
> > > question!
> > > Which has the highest ecological cost? A sheet of paper or constantly
> > > switching on your computer and connecting to the Internet to read your
> > > email?
> >
> >
> >
> >
> > --
> > Terry Ally
> > Twitter.com/terryally
> > Facebook.com/terryally
> > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > To print or not to print this email is the environmentally-searching 
> > question!
> > Which has the highest ecological cost? A sheet of paper or constantly 
> > switching on your computer and connecting to the Internet to read your 
> > email?
> >
> 
> 
> 
> 
> -- 
> Terry Ally
> Twitter.com/terryally
> Facebook.com/terryally
> ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> To print or not to print this email is the environmentally-searching question!
> Which has the highest ecological cost? A sheet of paper or constantly 
> switching on your computer and connecting to the Internet to read your email? 
> 



Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Terry Ally (Gmail)
Stuart,

I reversed it as you suggested and every future show is displaying as
having ended.

Terry

On 11 November 2012 19:11, Stuart Dallas  wrote:

> Please include the list when replying.
>
> On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)" 
> wrote:
>
> > What I want is the reverse.
> >
> > I want that if people attempt to access the show page after the show has
> ended that it triggers an error which takes it to another page. The actual
> conditional statement is as follows (which I will replace with timestamp):
> >
> >   $todaydate = date("D, M jS, Y g:i:s a");
> >   $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
> > if ($todaydate > $showenddate) {
> >   header( 'Location: eventdetails_error.php' ) ;
> >   }
>
> This is what you have:
>
> if ($todaydate > $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> That says: if the current time is later than the end date of the show,
> tell them the date of the show hasn't arrived yet.
>
> What you mean is: if the current time is later than the end of the show,
> tell them the show has ended.
>
> if ($todaydate < $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> It's a simple logic error.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
> > On 11 November 2012 19:04, Stuart Dallas  wrote:
> > On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)" 
> wrote:
> >
> > > Hi Shiplu and Stuart,
> > >
> > > Comparing timestamps was my first option. I've reinstated it. Have a
> look
> > > at http://www.lakesidesurrey.co.uk/test.php (show_source included)
> and you
> > > will see that PHP is still outputting the wrong thing.
> > >
> > > I just can't figure out what's wrong.
> >
> > Your comparison is backwards:
> >
> > if ($todaydate > $showenddate):
> >
> > should be
> >
> > if ($todaydate < $showenddate):
> >
> > -Stuart
> >
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
> >
> > > On 11 November 2012 18:48, shiplu  wrote:
> > >
> > >> You can always use timestamp which is integer.
> > >>
> > >> $todaydate = time();
> > >> $showenddate = strtotime($showsRecord['end_date']);
> > >>
> > >>
> > >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) <
> terrya...@gmail.com>wrote:
> > >>
> > >>> Hi all,
> > >>>
> > >>> I am having a problem with comparing time. I am using the following:
> > >>>
> > >>> $todaydate = date("D, M jS, Y g:i:s a");
> > >>> $showenddate = date("D, M jS, Y g:i:s a",
> > >>> strtotime($showsRecord['end_date']));
> > >>>
> > >>> if ($todaydate > $showenddate):
> > >>>echo "The date of the show has not yet arrived";
> > >>> else:
> > >>>echo "The show has ended";
> > >>> endif;
> > >>>
> > >>> The problem that I am encountering is that PHP is rendering the
> reverse of
> > >>> the equation. For example:
> > >>>
> > >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov
> 2012*,
> > >>> the message that I am getting is *the show has ended* which is
> wrong. A
> > >>>
> > >>> test example is at http://www.lakesidesurrey.co.uk/test.php.
> > >>>
> > >>> You can also me what I am doing wrong?
> > >>>
> > >>> Thanks
> > >>> Terry
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Shiplu.Mokadd.im
> > >> ImgSign.com | A dynamic signature machine
> > >> Innovation distinguishes between follower and leader
> > >>
> > >>
> > >
> > >
> > > --
> > > *Terry Ally*
> > > Twitter.com/terryally
> > > Facebook.com/terryally
> > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > > To print or not to print this email is the environmentally-searching
> > > question!
> > > Which has the highest ecological cost? A sheet of paper or constantly
> > > switching on your computer and connecting to the Internet to read your
> > > email?
> >
> >
> >
> >
> > --
> > Terry Ally
> > Twitter.com/terryally
> > Facebook.com/terryally
> > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > To print or not to print this email is the environmentally-searching
> question!
> > Which has the highest ecological cost? A sheet of paper or constantly
> switching on your computer and connecting to the Internet to read your
> email?
> >
>
>


-- 
*Terry Ally*
Twitter.com/terryally
Facebook.com/terryally
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
To print or not to print this email is the environmentally-searching
question!
Which has the highest ecological cost? A sheet of paper or constantly
switching on your computer and connecting to the Internet to read your
email?


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Stuart Dallas
Please include the list when replying.

On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)"  wrote:

> What I want is the reverse.
> 
> I want that if people attempt to access the show page after the show has 
> ended that it triggers an error which takes it to another page. The actual 
> conditional statement is as follows (which I will replace with timestamp):
> 
>   $todaydate = date("D, M jS, Y g:i:s a");
>   $showenddate = date("D, M jS, Y g:i:s a", 
> strtotime($showsRecord['end_date']));
> if ($todaydate > $showenddate) {
>   header( 'Location: eventdetails_error.php' ) ;
>   }

This is what you have:

if ($todaydate > $showenddate): 
echo "The date of the show has not yet arrived"; 
else:  
echo "The show has ended"; 
endif; 

That says: if the current time is later than the end date of the show, tell 
them the date of the show hasn't arrived yet.

What you mean is: if the current time is later than the end of the show, tell 
them the show has ended.

if ($todaydate < $showenddate): 
echo "The date of the show has not yet arrived"; 
else:  
echo "The show has ended"; 
endif; 

It's a simple logic error.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

> On 11 November 2012 19:04, Stuart Dallas  wrote:
> On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)"  wrote:
> 
> > Hi Shiplu and Stuart,
> >
> > Comparing timestamps was my first option. I've reinstated it. Have a look
> > at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you
> > will see that PHP is still outputting the wrong thing.
> >
> > I just can't figure out what's wrong.
> 
> Your comparison is backwards:
> 
> if ($todaydate > $showenddate):
> 
> should be
> 
> if ($todaydate < $showenddate):
> 
> -Stuart
> 
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
> 
> > On 11 November 2012 18:48, shiplu  wrote:
> >
> >> You can always use timestamp which is integer.
> >>
> >> $todaydate = time();
> >> $showenddate = strtotime($showsRecord['end_date']);
> >>
> >>
> >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) 
> >> wrote:
> >>
> >>> Hi all,
> >>>
> >>> I am having a problem with comparing time. I am using the following:
> >>>
> >>> $todaydate = date("D, M jS, Y g:i:s a");
> >>> $showenddate = date("D, M jS, Y g:i:s a",
> >>> strtotime($showsRecord['end_date']));
> >>>
> >>> if ($todaydate > $showenddate):
> >>>echo "The date of the show has not yet arrived";
> >>> else:
> >>>echo "The show has ended";
> >>> endif;
> >>>
> >>> The problem that I am encountering is that PHP is rendering the reverse of
> >>> the equation. For example:
> >>>
> >>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> >>> the message that I am getting is *the show has ended* which is wrong. A
> >>>
> >>> test example is at http://www.lakesidesurrey.co.uk/test.php.
> >>>
> >>> You can also me what I am doing wrong?
> >>>
> >>> Thanks
> >>> Terry
> >>>
> >>
> >>
> >>
> >> --
> >> Shiplu.Mokadd.im
> >> ImgSign.com | A dynamic signature machine
> >> Innovation distinguishes between follower and leader
> >>
> >>
> >
> >
> > --
> > *Terry Ally*
> > Twitter.com/terryally
> > Facebook.com/terryally
> > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > To print or not to print this email is the environmentally-searching
> > question!
> > Which has the highest ecological cost? A sheet of paper or constantly
> > switching on your computer and connecting to the Internet to read your
> > email?
> 
> 
> 
> 
> -- 
> Terry Ally
> Twitter.com/terryally
> Facebook.com/terryally
> ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> To print or not to print this email is the environmentally-searching question!
> Which has the highest ecological cost? A sheet of paper or constantly 
> switching on your computer and connecting to the Internet to read your email? 
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Stuart Dallas
On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)"  wrote:

> Hi Shiplu and Stuart,
> 
> Comparing timestamps was my first option. I've reinstated it. Have a look
> at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you
> will see that PHP is still outputting the wrong thing.
> 
> I just can't figure out what's wrong.

Your comparison is backwards:

if ($todaydate > $showenddate):

should be

if ($todaydate < $showenddate):

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

> On 11 November 2012 18:48, shiplu  wrote:
> 
>> You can always use timestamp which is integer.
>> 
>> $todaydate = time();
>> $showenddate = strtotime($showsRecord['end_date']);
>> 
>> 
>> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) 
>> wrote:
>> 
>>> Hi all,
>>> 
>>> I am having a problem with comparing time. I am using the following:
>>> 
>>> $todaydate = date("D, M jS, Y g:i:s a");
>>> $showenddate = date("D, M jS, Y g:i:s a",
>>> strtotime($showsRecord['end_date']));
>>> 
>>> if ($todaydate > $showenddate):
>>>echo "The date of the show has not yet arrived";
>>> else:
>>>echo "The show has ended";
>>> endif;
>>> 
>>> The problem that I am encountering is that PHP is rendering the reverse of
>>> the equation. For example:
>>> 
>>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
>>> the message that I am getting is *the show has ended* which is wrong. A
>>> 
>>> test example is at http://www.lakesidesurrey.co.uk/test.php.
>>> 
>>> You can also me what I am doing wrong?
>>> 
>>> Thanks
>>> Terry
>>> 
>> 
>> 
>> 
>> --
>> Shiplu.Mokadd.im
>> ImgSign.com | A dynamic signature machine
>> Innovation distinguishes between follower and leader
>> 
>> 
> 
> 
> -- 
> *Terry Ally*
> Twitter.com/terryally
> Facebook.com/terryally
> ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> To print or not to print this email is the environmentally-searching
> question!
> Which has the highest ecological cost? A sheet of paper or constantly
> switching on your computer and connecting to the Internet to read your
> email?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Terry Ally (Gmail)
Hi Shiplu and Stuart,

Comparing timestamps was my first option. I've reinstated it. Have a look
at http://www.lakesidesurrey.co.uk/test.php (show_source included) and you
will see that PHP is still outputting the wrong thing.

I just can't figure out what's wrong.

Terry

On 11 November 2012 18:48, shiplu  wrote:

> You can always use timestamp which is integer.
>
> $todaydate = time();
> $showenddate = strtotime($showsRecord['end_date']);
>
>
> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) 
> wrote:
>
>> Hi all,
>>
>> I am having a problem with comparing time. I am using the following:
>>
>> $todaydate = date("D, M jS, Y g:i:s a");
>> $showenddate = date("D, M jS, Y g:i:s a",
>> strtotime($showsRecord['end_date']));
>>
>> if ($todaydate > $showenddate):
>> echo "The date of the show has not yet arrived";
>> else:
>> echo "The show has ended";
>> endif;
>>
>> The problem that I am encountering is that PHP is rendering the reverse of
>> the equation. For example:
>>
>> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
>> the message that I am getting is *the show has ended* which is wrong. A
>>
>> test example is at http://www.lakesidesurrey.co.uk/test.php.
>>
>> You can also me what I am doing wrong?
>>
>> Thanks
>> Terry
>>
>
>
>
> --
> Shiplu.Mokadd.im
> ImgSign.com | A dynamic signature machine
> Innovation distinguishes between follower and leader
>
>


-- 
*Terry Ally*
Twitter.com/terryally
Facebook.com/terryally
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
To print or not to print this email is the environmentally-searching
question!
Which has the highest ecological cost? A sheet of paper or constantly
switching on your computer and connecting to the Internet to read your
email?


Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread Stuart Dallas
On 11 Nov 2012, at 18:30, "Terry Ally (Gmail)"  wrote:

> I am having a problem with comparing time. I am using the following:
> 
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));

The date function returns a string.

> if ($todaydate > $showenddate):
>echo "The date of the show has not yet arrived";
> else:
>echo "The show has ended";
> endif;

So here you are comparing two strings; PHP has no idea they are dates.

> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
> 
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
> 
> You can also me what I am doing wrong?


Compare timestamps instead, i.e. time() for the current time, and what you get 
back from strtotime for the end date.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

Re: [PHP] Date comparison going wrong, wrong, wrong

2012-11-11 Thread shiplu
You can always use timestamp which is integer.

$todaydate = time();
$showenddate = strtotime($showsRecord['end_date']);


On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) wrote:

> Hi all,
>
> I am having a problem with comparing time. I am using the following:
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
>
> if ($todaydate > $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
>
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
>
> You can also me what I am doing wrong?
>
> Thanks
> Terry
>



-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] Date manipulation

2012-10-25 Thread Daniel Brown
On Thu, Oct 25, 2012 at 3:06 PM, Ron Piggott
 wrote:
>
> Is it possible for PHP to accept the following as a date:
>
> 04:11:22 Aug 21, 2011 PDT
>
> so I may output it as:
>
> gmdate(‘Y-m-d H:i:s’)
>
> - I want the time zone included

Sure.



-- 

Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Date manipulation

2012-10-25 Thread Ron Piggott

Is it possible for PHP to accept the following as a date:

04:11:22 Aug 21, 2011 PDT

so I may output it as:

gmdate(‘Y-m-d H:i:s’)

- I want the time zone included

Ron


Ron Piggott



www.TheVerseOfTheDay.info 


Re: [PHP] date conversion/extraction issues

2012-05-03 Thread Terry Ally (Gmail)
Haluk,

After you retrieve the date from the database you still have to convert it
from a string to time and then to a date. Try:




Terry

On 2 May 2012 22:36, Haluk Karamete  wrote:

> This is my code and the output is right after that...
>
> $PDate = $row['PDate'];
> //row is tapping into ms-sql date field.
> //and the ms-sql data field has a value like this for the PDate;
> //07/12/2001
> $PDate = $PDate->date;
> echo "[", $PDate , "]";
> echo "[", var_dump($row['PDate']) , "]";
> echo "[", serialize($row['PDate']) , "]";
> the output is as follows. And my question is embedded in the output.
>
> []  ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00?
>
> [object(DateTime)#3 (3) { ["date"]=> string(19) "2001-12-07 00:00:00"
> ["timezone_type"]=> int(3) ["timezone"]=> string(19)
> "America/Los_Angeles" } ]
>
> [O:8:"DateTime":3:{s:4:"date";s:19:"2001-12-07
>
> 00:00:00";s:13:"timezone_type";i:3;s:8:"timezone";s:19:"America/Los_Angeles";}]
>
> if I were to directly insert the $row['date']  ms-sql value into mysq,
> I get this error;
> Catchable fatal error: Object of class DateTime could not be converted
> to string in sql.php on line 379
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
*Terry Ally*
Twitter.com/terryally
Facebook.com/terryally
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
To print or not to print this email is the environmentally-searching
question!
Which has the highest ecological cost? A sheet of paper or constantly
switching on your computer and connecting to the Internet to read your
email?


Re: [PHP] date conversion/extraction issues

2012-05-02 Thread Jim Lucas

On 05/02/2012 02:36 PM, Haluk Karamete wrote:

This is my code and the output is right after that...

$PDate = $row['PDate'];
//row is tapping into ms-sql date field.
//and the ms-sql data field has a value like this for the PDate;
//07/12/2001
$PDate = $PDate->date;
echo "[", $PDate , "]";
echo "[", var_dump($row['PDate']) , "]";
echo "[", serialize($row['PDate']) , "]";
the output is as follows. And my question is embedded in the output.

[]  ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00?

[object(DateTime)#3 (3) { ["date"]=>  string(19) "2001-12-07 00:00:00"
["timezone_type"]=>  int(3) ["timezone"]=>  string(19)
"America/Los_Angeles" } ]

[O:8:"DateTime":3:{s:4:"date";s:19:"2001-12-07
00:00:00";s:13:"timezone_type";i:3;s:8:"timezone";s:19:"America/Los_Angeles";}]

if I were to directly insert the $row['date']  ms-sql value into mysq,
I get this error;
Catchable fatal error: Object of class DateTime could not be converted
to string in sql.php on line 379



I think you need to double check your variable names.  In one place you 
are using $row['PDate'] in another you are referring to $row['date']


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date conversion/extraction issues

2012-05-02 Thread Matijn Woudt
On Wed, May 2, 2012 at 11:36 PM, Haluk Karamete  wrote:
> This is my code and the output is right after that...
>
> $PDate = $row['PDate'];
> //row is tapping into ms-sql date field.
> //and the ms-sql data field has a value like this for the PDate;
> //07/12/2001
> $PDate = $PDate->date;
> echo "[", $PDate , "]";
> echo "[", var_dump($row['PDate']) , "]";
> echo "[", serialize($row['PDate']) , "]";
> the output is as follows. And my question is embedded in the output.
>
> []      ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00?
>
> [object(DateTime)#3 (3) { ["date"]=> string(19) "2001-12-07 00:00:00"
> ["timezone_type"]=> int(3) ["timezone"]=> string(19)
> "America/Los_Angeles" } ]
>
> [O:8:"DateTime":3:{s:4:"date";s:19:"2001-12-07
> 00:00:00";s:13:"timezone_type";i:3;s:8:"timezone";s:19:"America/Los_Angeles";}]
>
> if I were to directly insert the $row['date']  ms-sql value into mysq,
> I get this error;
> Catchable fatal error: Object of class DateTime could not be converted
> to string in sql.php on line 379
>

Have you enabled all warnings in PHP, and checked the Apache error log
after that? It probably contains a hint on why it doesn't work...

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] date conversion/extraction issues

2012-05-02 Thread Haluk Karamete
This is my code and the output is right after that...

$PDate = $row['PDate'];
//row is tapping into ms-sql date field.
//and the ms-sql data field has a value like this for the PDate;
//07/12/2001
$PDate = $PDate->date;
echo "[", $PDate , "]";
echo "[", var_dump($row['PDate']) , "]";
echo "[", serialize($row['PDate']) , "]";
the output is as follows. And my question is embedded in the output.

[]  ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00?

[object(DateTime)#3 (3) { ["date"]=> string(19) "2001-12-07 00:00:00"
["timezone_type"]=> int(3) ["timezone"]=> string(19)
"America/Los_Angeles" } ]

[O:8:"DateTime":3:{s:4:"date";s:19:"2001-12-07
00:00:00";s:13:"timezone_type";i:3;s:8:"timezone";s:19:"America/Los_Angeles";}]

if I were to directly insert the $row['date']  ms-sql value into mysq,
I get this error;
Catchable fatal error: Object of class DateTime could not be converted
to string in sql.php on line 379

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date() confustion

2012-04-26 Thread ma...@behnke.biz


Nathan Nobbe  hat am 26. April 2012 um 06:40
geschrieben:
>
> INSERT TIMESTAMP:  1335414561
> INSERT DATE TIME:  2012-04-26 4:29:21
>
> But then from the interactive interpreter on the same box (same php.ini
as
> well):
>
> php > echo date("Y-m-d G:i:s", 1335414561);
> 2012-04-25 22:29:21
>
> I get this same output from another random computer of mine and I've
> verified date.timezone is consistent in both environments.
>

This definitly looks like a timezone offset!
Try the following code in your environments.

$date  = new  DateTime ( );
$tz  =  $date -> getTimezone ();
echo  $tz -> getName ();


PHP for CLI mode has a different php.ini than the one for apache2. Maybe
that is a problem?

Check also


php -i | grep "date.timezone"


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date() confustion

2012-04-25 Thread Nathan Nobbe
On Wed, Apr 25, 2012 at 10:44 PM, Simon J Welsh  wrote:

> On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:
>
> > Hi everyone,
> >
> > Does anybody know what might influence the output of the date() function
> > besides date.timezone setting?
> >
> > Running through some code in an app I'm working on, I have this code:
> >
> > $timestamp = time();
> > $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
> >
> > Logging these values yields:
> >
> > INSERT TIMESTAMP:  1335414561
> > INSERT DATE TIME:  2012-04-26 4:29:21
> >
> > But then from the interactive interpreter on the same box (same php.ini
> as
> > well):
> >
> > php > echo date("Y-m-d G:i:s", 1335414561);
> > 2012-04-25 22:29:21
> >
> > I get this same output from another random computer of mine and I've
> > verified date.timezone is consistent in both environments.
> >
> > Something's going on in the first case, but I'm unsure what; any ideas?
> >
> > Your help appreciated as always.
> >
> > -nathan
>
>
> A call to date_default_timezone_set() during execution can change the
> timezone. If you add echo date_default_timezone_get(); just before this,
> does it give the same output as your date.timezone setting?
>

Simon,

I was dumping out the value from ini_get('date.timezone'); seems it must be
getting set at runtime.

Thanks!

-nathan


Re: [PHP] date() confustion

2012-04-25 Thread Simon J Welsh
On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:

> Hi everyone,
> 
> Does anybody know what might influence the output of the date() function
> besides date.timezone setting?
> 
> Running through some code in an app I'm working on, I have this code:
> 
> $timestamp = time();
> $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
> 
> Logging these values yields:
> 
> INSERT TIMESTAMP:  1335414561
> INSERT DATE TIME:  2012-04-26 4:29:21
> 
> But then from the interactive interpreter on the same box (same php.ini as
> well):
> 
> php > echo date("Y-m-d G:i:s", 1335414561);
> 2012-04-25 22:29:21
> 
> I get this same output from another random computer of mine and I've
> verified date.timezone is consistent in both environments.
> 
> Something's going on in the first case, but I'm unsure what; any ideas?
> 
> Your help appreciated as always.
> 
> -nathan


A call to date_default_timezone_set() during execution can change the timezone. 
If you add echo date_default_timezone_get(); just before this, does it give the 
same output as your date.timezone setting?

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] date() confustion

2012-04-25 Thread Nathan Nobbe
Hi everyone,

Does anybody know what might influence the output of the date() function
besides date.timezone setting?

Running through some code in an app I'm working on, I have this code:

$timestamp = time();
$mysqlDatetime = date("Y-m-d G:i:s", $timestamp);

Logging these values yields:

INSERT TIMESTAMP:  1335414561
INSERT DATE TIME:  2012-04-26 4:29:21

But then from the interactive interpreter on the same box (same php.ini as
well):

php > echo date("Y-m-d G:i:s", 1335414561);
2012-04-25 22:29:21

I get this same output from another random computer of mine and I've
verified date.timezone is consistent in both environments.

Something's going on in the first case, but I'm unsure what; any ideas?

Your help appreciated as always.

-nathan


Re: [PHP] Date function kill lots time !

2012-01-05 Thread xucheng
yes,it is set in php.ini .

2012/1/5 Adam Richardson 

> On Wed, Jan 4, 2012 at 11:07 PM, xucheng wrote:
>
>> hi all,
>>   I have a webapp which track visitors, and use xhprof for profiling my
>> codes .
>>   After reading some reports produced by xhprof, i found that function
>> Date() kills most time of my app !
>>   how can this happen ? Is this function has some internal issue that i
>> should kown ?
>>   Any comment appreciate ! thanks !
>>
>> --
>> RTFSC - Read The F**king Source Code :)!
>>
>
>
> Did you set the timezone? If not, PHP raises a notice, which causes
> terrible performance (see the comment at the bottom):
> https://bugs.php.net/bug.php?id=39968
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com
>



-- 
RTFSC - Read The F**king Source Code :)!


Re: [PHP] Date function kill lots time !

2012-01-04 Thread Adam Richardson
On Wed, Jan 4, 2012 at 11:07 PM, xucheng  wrote:

> hi all,
>   I have a webapp which track visitors, and use xhprof for profiling my
> codes .
>   After reading some reports produced by xhprof, i found that function
> Date() kills most time of my app !
>   how can this happen ? Is this function has some internal issue that i
> should kown ?
>   Any comment appreciate ! thanks !
>
> --
> RTFSC - Read The F**king Source Code :)!
>


Did you set the timezone? If not, PHP raises a notice, which causes
terrible performance (see the comment at the bottom):
https://bugs.php.net/bug.php?id=39968

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Date function kill lots time !

2012-01-04 Thread xucheng
hi all,
   I have a webapp which track visitors, and use xhprof for profiling my
codes .
   After reading some reports produced by xhprof, i found that function
Date() kills most time of my app !
   how can this happen ? Is this function has some internal issue that i
should kown ?
   Any comment appreciate ! thanks !

-- 
RTFSC - Read The F**king Source Code :)!


[PHP] Date validation

2011-05-20 Thread Geoff Lane
Hi All,

I'm scratching my head trying to remember how I validated string
representation of dates 'the first time around' with PHP (before going
over to ASP/VBScript for almost a decade). I have a feeling that I
must have rolled my own validation function, because I can't find
anything other than strtotime() and checkdate() in PHP itself.

Although checkdate() seems fine, strtotime() appears to be 'broken'.
It seems where possible to return a timestamp that makes some sense
rather than return FALSE when handed an invalid date. For example,
strtotime('30 Feb 1999') returns 920332800, which is equivalent to
strtotime('02 Mar 1999'). When I ask a user to enter a date and they
make a typo, forget that September only has 30 days, etc., I want to
be able to detect the problem rather than post a date in the following
month!

It also seems that where the DateTime class uses string representation
of dates, times, or intervals that these must be 'in a format accepted
by strtotime()'; which implies that 'under the hood' strtotime() is
used to convert the string to a date/time value, which implies that
the Date/Time class cannot properly handle string input values.

This seems to be such a common requirement that I suspect I've missed
something basic. I'd thus be grateful for any pointers as to how to
properly validate user-input string representation of dates.

Cheers,

-- 
Geoff Lane


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2011-04-02 Thread Dan Dan
It seems different php versions have different outputs for this code:

Fedora Core 14 (x86):

first: 01-03-2011 00:00:00
second: 08-03-2011 00:00:00
third: 22-03-2011 00:00:00
fourth: 22-03-2011 00:00:00
fifth: 29-03-2011 00:00:00

Fedora Core11 (x86_64):

first: 31-12-1969 16:00:00
second: 31-12-1969 16:00:00
third: 22-03-2011 00:00:00
fourth: 31-12-1969 16:00:00
fifth: 31-12-1969 16:00:00

However it works if reorder Year and Month like:

echo "first: ".date("d-m-Y H:i:s",strtotime('2011 March first
wednesday'))."\n";
echo "second: ".date("d-m-Y H:i:s",strtotime('2011 March second
wednesday'))."\n";
echo "third: ".date("d-m-Y H:i:s",strtotime('2011 March third
wednesday'))."\n";
echo "fourth: ".date("d-m-Y H:i:s",strtotime('2011 March fourth
wednesday'))."\n";
echo "fifth: ".date("d-m-Y H:i:s",strtotime('2011 March fifth
wednesday'))."\n";

first: 02-03-2011 00:00:00
second: 09-03-2011 00:00:00
third: 16-03-2011 00:00:00
fourth: 23-03-2011 00:00:00
fifth: 30-03-2011 00:00:00

Thanks
-dani


On Sat, Apr 2, 2011 at 1:17 AM, Louis Huppenbauer <
louis.huppenba...@gmail.com> wrote:

> Just try "of March". Worked for me.
>
>
> print "first: ".date("d-m-Y H:i:s",strtotime('first Tuesday of March
> 2011'))."\n";
> print "second: ".date("d-m-Y H:i:s",strtotime('second Tuesday of March
> 2011'))."\n";
> print "third: ".date("d-m-Y H:i:s",strtotime('third Tuesday of March
> 2011'))."\n";
> print "fourth: ".date("d-m-Y H:i:s",strtotime('fourth Tuesday of March
> 2011'))."\n";
> print "fifth: ".date("d-m-Y H:i:s",strtotime('fifth Tuesday of March
> 2011'))."\n";
>
>
> 2011/4/2 Dan Dan :
> > I removed the day (1 before the March), but its still giving the same
> > result, i.e. different days of month with and without the 'first'. Any
> > further help ?
> >
> > print "first Tuesday :".date("d-m-Y H:i:s",strtotime('March 2011
> > Tuesday'))."\n";
> > print "first: ".date("d-m-Y H:i:s",strtotime('March 2011 first
> > Tuesday'))."\n";
> > print "second: ".date("d-m-Y H:i:s",strtotime('March 2011 second
> > Tuesday'))."\n";
> > print "third: ".date("d-m-Y H:i:s",strtotime('March 2011 third
> > Tuesday'))."\n";
> > print "fourth: ".date("d-m-Y H:i:s",strtotime('March 2011 fourth
> > Tuesday'))."\n";
> >
> > first Tuesday :01-03-2011 00:00:00
> > first: 08-03-2011 00:00:00
> > second: 15-03-2011 00:00:00
> > third: 22-03-2011 00:00:00
> > fourth: 29-03-2011 00:00:00
> >
> > Thanks
> > -dani
> >
> >
> >
> > On Fri, Apr 1, 2011 at 9:37 AM, Daniel Brown  wrote:
> >
> >> On Fri, Apr 1, 2011 at 12:35, Dan Dan  wrote:
> >> > Hi Folks,
> >> >
> >> > I am trying to get the day of month for a particular day of week (e.g.
> >> > Tuesday) for the first, second, third, fourth week in a month. The
> code i
> >> > have seems issues in March, but works e.g. in April:
> >> >
> >> > print date("d-m-Y H:i:s",strtotime('1 March 2011 Tuesday'));
> >> >>> 01-03-2011 00:00:00
> >> >
> >> > print date("d-m-Y H:i:s",strtotime('1 March 2011 first Tuesday'));
> >> >>> 08-03-2011 00:00:00
> >> >
> >> > While in April, I have
> >> >
> >> > print date("d-m-Y H:i:s",strtotime('1 April 2011 Tuesday'));
> >> >>> 05-04-2011 00:00:00
> >> >
> >> > print date("d-m-Y H:i:s",strtotime('1 April 2011 first Tuesday'));
> >> >>> 05-04-2011 00:00:00
> >> >
> >> > Could someone help whats wrong with the technique i am trying to find
> >> that
> >> > day of month. Is there any better way ?
> >>
> >> Because you're combining the date with the day of the week.  It so
> >> happens that 1 March was a Tuesday, but today - 1 April - is a Friday.
> >>  Pick one or the other, not both.
> >>
> >> --
> >> 
> >> Network Infrastructure Manager
> >> http://www.php.net/
> >>
> >
>


Re: [PHP] date problem

2011-04-02 Thread Louis Huppenbauer
Just try "of March". Worked for me.


print "first: ".date("d-m-Y H:i:s",strtotime('first Tuesday of March
2011'))."\n";
print "second: ".date("d-m-Y H:i:s",strtotime('second Tuesday of March
2011'))."\n";
print "third: ".date("d-m-Y H:i:s",strtotime('third Tuesday of March
2011'))."\n";
print "fourth: ".date("d-m-Y H:i:s",strtotime('fourth Tuesday of March
2011'))."\n";
print "fifth: ".date("d-m-Y H:i:s",strtotime('fifth Tuesday of March
2011'))."\n";


2011/4/2 Dan Dan :
> I removed the day (1 before the March), but its still giving the same
> result, i.e. different days of month with and without the 'first'. Any
> further help ?
>
> print "first Tuesday :".date("d-m-Y H:i:s",strtotime('March 2011
> Tuesday'))."\n";
> print "first: ".date("d-m-Y H:i:s",strtotime('March 2011 first
> Tuesday'))."\n";
> print "second: ".date("d-m-Y H:i:s",strtotime('March 2011 second
> Tuesday'))."\n";
> print "third: ".date("d-m-Y H:i:s",strtotime('March 2011 third
> Tuesday'))."\n";
> print "fourth: ".date("d-m-Y H:i:s",strtotime('March 2011 fourth
> Tuesday'))."\n";
>
> first Tuesday :01-03-2011 00:00:00
> first: 08-03-2011 00:00:00
> second: 15-03-2011 00:00:00
> third: 22-03-2011 00:00:00
> fourth: 29-03-2011 00:00:00
>
> Thanks
> -dani
>
>
>
> On Fri, Apr 1, 2011 at 9:37 AM, Daniel Brown  wrote:
>
>> On Fri, Apr 1, 2011 at 12:35, Dan Dan  wrote:
>> > Hi Folks,
>> >
>> > I am trying to get the day of month for a particular day of week (e.g.
>> > Tuesday) for the first, second, third, fourth week in a month. The code i
>> > have seems issues in March, but works e.g. in April:
>> >
>> > print date("d-m-Y H:i:s",strtotime('1 March 2011 Tuesday'));
>> >>> 01-03-2011 00:00:00
>> >
>> > print date("d-m-Y H:i:s",strtotime('1 March 2011 first Tuesday'));
>> >>> 08-03-2011 00:00:00
>> >
>> > While in April, I have
>> >
>> > print date("d-m-Y H:i:s",strtotime('1 April 2011 Tuesday'));
>> >>> 05-04-2011 00:00:00
>> >
>> > print date("d-m-Y H:i:s",strtotime('1 April 2011 first Tuesday'));
>> >>> 05-04-2011 00:00:00
>> >
>> > Could someone help whats wrong with the technique i am trying to find
>> that
>> > day of month. Is there any better way ?
>>
>>     Because you're combining the date with the day of the week.  It so
>> happens that 1 March was a Tuesday, but today - 1 April - is a Friday.
>>  Pick one or the other, not both.
>>
>> --
>> 
>> Network Infrastructure Manager
>> http://www.php.net/
>>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2011-04-01 Thread Dan Dan
I removed the day (1 before the March), but its still giving the same
result, i.e. different days of month with and without the 'first'. Any
further help ?

print "first Tuesday :".date("d-m-Y H:i:s",strtotime('March 2011
Tuesday'))."\n";
print "first: ".date("d-m-Y H:i:s",strtotime('March 2011 first
Tuesday'))."\n";
print "second: ".date("d-m-Y H:i:s",strtotime('March 2011 second
Tuesday'))."\n";
print "third: ".date("d-m-Y H:i:s",strtotime('March 2011 third
Tuesday'))."\n";
print "fourth: ".date("d-m-Y H:i:s",strtotime('March 2011 fourth
Tuesday'))."\n";

first Tuesday :01-03-2011 00:00:00
first: 08-03-2011 00:00:00
second: 15-03-2011 00:00:00
third: 22-03-2011 00:00:00
fourth: 29-03-2011 00:00:00

Thanks
-dani



On Fri, Apr 1, 2011 at 9:37 AM, Daniel Brown  wrote:

> On Fri, Apr 1, 2011 at 12:35, Dan Dan  wrote:
> > Hi Folks,
> >
> > I am trying to get the day of month for a particular day of week (e.g.
> > Tuesday) for the first, second, third, fourth week in a month. The code i
> > have seems issues in March, but works e.g. in April:
> >
> > print date("d-m-Y H:i:s",strtotime('1 March 2011 Tuesday'));
> >>> 01-03-2011 00:00:00
> >
> > print date("d-m-Y H:i:s",strtotime('1 March 2011 first Tuesday'));
> >>> 08-03-2011 00:00:00
> >
> > While in April, I have
> >
> > print date("d-m-Y H:i:s",strtotime('1 April 2011 Tuesday'));
> >>> 05-04-2011 00:00:00
> >
> > print date("d-m-Y H:i:s",strtotime('1 April 2011 first Tuesday'));
> >>> 05-04-2011 00:00:00
> >
> > Could someone help whats wrong with the technique i am trying to find
> that
> > day of month. Is there any better way ?
>
> Because you're combining the date with the day of the week.  It so
> happens that 1 March was a Tuesday, but today - 1 April - is a Friday.
>  Pick one or the other, not both.
>
> --
> 
> Network Infrastructure Manager
> http://www.php.net/
>


Re: [PHP] date problem

2011-04-01 Thread Daniel Brown
On Fri, Apr 1, 2011 at 12:35, Dan Dan  wrote:
> Hi Folks,
>
> I am trying to get the day of month for a particular day of week (e.g.
> Tuesday) for the first, second, third, fourth week in a month. The code i
> have seems issues in March, but works e.g. in April:
>
> print date("d-m-Y H:i:s",strtotime('1 March 2011 Tuesday'));
>>> 01-03-2011 00:00:00
>
> print date("d-m-Y H:i:s",strtotime('1 March 2011 first Tuesday'));
>>> 08-03-2011 00:00:00
>
> While in April, I have
>
> print date("d-m-Y H:i:s",strtotime('1 April 2011 Tuesday'));
>>> 05-04-2011 00:00:00
>
> print date("d-m-Y H:i:s",strtotime('1 April 2011 first Tuesday'));
>>> 05-04-2011 00:00:00
>
> Could someone help whats wrong with the technique i am trying to find that
> day of month. Is there any better way ?

Because you're combining the date with the day of the week.  It so
happens that 1 March was a Tuesday, but today - 1 April - is a Friday.
 Pick one or the other, not both.

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] date problem

2011-04-01 Thread Dan Dan
Hi Folks,

I am trying to get the day of month for a particular day of week (e.g.
Tuesday) for the first, second, third, fourth week in a month. The code i
have seems issues in March, but works e.g. in April:

print date("d-m-Y H:i:s",strtotime('1 March 2011 Tuesday'));
>> 01-03-2011 00:00:00

print date("d-m-Y H:i:s",strtotime('1 March 2011 first Tuesday'));
>> 08-03-2011 00:00:00

While in April, I have

print date("d-m-Y H:i:s",strtotime('1 April 2011 Tuesday'));
>> 05-04-2011 00:00:00

print date("d-m-Y H:i:s",strtotime('1 April 2011 first Tuesday'));
>> 05-04-2011 00:00:00

Could someone help whats wrong with the technique i am trying to find that
day of month. Is there any better way ?

Thanks
-dani


Re: [PHP] Date Test...

2010-07-08 Thread Don Wieland

On Jul 8, 2010, at 10:09 AM, Ashley Sheridan wrote:

thanks Ash,

I figure it out. I was not entering the full year.


date('y-m-d',strtotime($fval))

needed to be

date('o-m-d',strtotime($fval))

Duh ;-)

Thanks,

Don


On Wed, 2010-07-07 at 13:28 -0700, Don Wieland wrote:


Hello all,

I am processing an array to build an INSERT string in PHP. The code
below I build an a separate array for the TARGET fields and the  
VALUES.


I am trying to trap for a NULL ENTRY in a Date Input Field. Date
fields are identified with: $ffield['s']=='/'

I tried to add the "&& !empty($fval)" to the test but it is giving my
an unexpected results. In my case, I have a Data of Birth field that
keeps populating in the future:  So 1941-06-16  inserts in the DB as
2041-06-16.

foreach($form_fields as $ffield){
$fval = is_array($ffield['f'])?joinFields($ffield['s'],
$ffield['f']):$_POST[$ffield['f']];
$query_values[] = 
"'".mysql_real_escape_string($ffield['s']=='/'
&& !empty($fval) ?date('y-m-d',strtotime($fval)):$fval)."'";
}

Will anyone point out the problem with this CODE?

Don Wieland



I can't see anything immediately wrong, but the tertiary operators  
here mixed in with the mysql_ function and string concatenation  
don't make for easy reading! Maybe add some brackets to partition  
things off a bit to make the code easier on the eye. :p


Have you tried echo'ing out the queries to see if they actually look  
well-formed? One place it could fall over is if the values you're  
using in it aren't well formed.


Lastly, you're using a $_POST field directly in your query if the  
first tertiary if/else fails. You should at the very least validate  
it to make sure it's in the form you expect, which has to at least  
be something that can be parsed and processed by strtotime() which  
you're using in your example.


Thanks,
Ash
http://www.ashleysheridan.co.uk


Don Wieland
D W   D a t a   C o n c e p t s
~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our  
Developer Support Plan at:

http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro  
9 or higher

http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html



Re: [PHP] Date Test...

2010-07-08 Thread Ashley Sheridan
On Wed, 2010-07-07 at 13:28 -0700, Don Wieland wrote:

> Hello all,
> 
> I am processing an array to build an INSERT string in PHP. The code  
> below I build an a separate array for the TARGET fields and the VALUES.
> 
> I am trying to trap for a NULL ENTRY in a Date Input Field. Date  
> fields are identified with: $ffield['s']=='/'
> 
> I tried to add the "&& !empty($fval)" to the test but it is giving my  
> an unexpected results. In my case, I have a Data of Birth field that  
> keeps populating in the future:  So 1941-06-16  inserts in the DB as  
> 2041-06-16.
> 
> foreach($form_fields as $ffield){
>   $fval = is_array($ffield['f'])?joinFields($ffield['s'], 
> $ffield['f']):$_POST[$ffield['f']];
>   $query_values[] = 
> "'".mysql_real_escape_string($ffield['s']=='/'  
> && !empty($fval) ?date('y-m-d',strtotime($fval)):$fval)."'";
>   }
> 
> Will anyone point out the problem with this CODE?
> 
> Don Wieland
> 


I can't see anything immediately wrong, but the tertiary operators here
mixed in with the mysql_ function and string concatenation don't make
for easy reading! Maybe add some brackets to partition things off a bit
to make the code easier on the eye. :p

Have you tried echo'ing out the queries to see if they actually look
well-formed? One place it could fall over is if the values you're using
in it aren't well formed.

Lastly, you're using a $_POST field directly in your query if the first
tertiary if/else fails. You should at the very least validate it to make
sure it's in the form you expect, which has to at least be something
that can be parsed and processed by strtotime() which you're using in
your example.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Date Test...

2010-07-07 Thread Don Wieland

Hello all,

I am processing an array to build an INSERT string in PHP. The code  
below I build an a separate array for the TARGET fields and the VALUES.


I am trying to trap for a NULL ENTRY in a Date Input Field. Date  
fields are identified with: $ffield['s']=='/'


I tried to add the "&& !empty($fval)" to the test but it is giving my  
an unexpected results. In my case, I have a Data of Birth field that  
keeps populating in the future:  So 1941-06-16  inserts in the DB as  
2041-06-16.


foreach($form_fields as $ffield){
			$fval = is_array($ffield['f'])?joinFields($ffield['s'], 
$ffield['f']):$_POST[$ffield['f']];
			$query_values[] = "'".mysql_real_escape_string($ffield['s']=='/'  
&& !empty($fval) ?date('y-m-d',strtotime($fval)):$fval)."'";

}

Will anyone point out the problem with this CODE?

Don Wieland

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date Conversion Problem

2010-06-18 Thread David Stoltz
No Problem Shreyas,

 

My original PHP code was writing the date like this:

echo date('l jS \of F Y h:i:s A'); //  - Thursday 17th of June 2010
08:58:02 AM

 

I changed it to this:

echo date('n\/j\/Y h:i:s A');//   - 6/17/2010 08:58:02 AM

 

Now that it was writing to the database correctly, I ran the following
script below to update all the rows that were improperly formatted.
After the below script ran, I didn't even have to convert the column to
datetime, since the SQL convert statement would now easily convert the
string to date - although the proper thing to do would be to convert the
column to date/time type. 

 

The below script was written in classic ASP- I've added a commented out
string below each step so you can see the changes being made to the
string:

 

<%

'This script was used to convert invalid php dates into true date
formats in the DB

 

set conn = Server.CreateObject("ADODB.Connection")

conn.open = "My DB Conncetion String"

 

set rs = conn.execute("SELECT id, employee_signed_on FROM TABLE1 WHERE
employee_signed_on is not null")

 

do while not rs.eof

 

id = rs("id")

temp = rs("employee_signed_on")

oldDate = rs("employee_signed_on")

'''''''''''''''''''''''''''''''''''''Thursday 17th of
June 2010 08:58:02 AM

 

oldDate = replace(oldDate,"Monday ","")

oldDate = replace(oldDate,"Tuesday ","")

oldDate = replace(oldDate,"Wednesday ","")

oldDate = replace(oldDate,"Thursday ","")

oldDate = replace(oldDate,"Friday ","")

oldDate = replace(oldDate,"Saturday ","")

oldDate = replace(oldDate,"Sunday ","")

'''''''''''''''''''''''''''''''''''''17th of June 2010
08:58:02 AM



oldDate = replace(oldDate,"th of ","/")

oldDate = replace(oldDate,"nd of ","/")

oldDate = replace(oldDate,"st of ","/")

oldDate = replace(oldDate,"rd of ","/")

'''''''''''''''''''''''''''''''''''''17/June 2010
08:58:02 AM



oldDate = replace(oldDate,"January ","1/")

oldDate = replace(oldDate,"February ","2/")

oldDate = replace(oldDate,"March ","3/")

oldDate = replace(oldDate,"April ","4/")

oldDate = replace(oldDate,"May ","5/")

oldDate = replace(oldDate,"June ","6/")

oldDate = replace(oldDate,"July ","7/")

oldDate = replace(oldDate,"August ","8/")

oldDate = replace(oldDate,"September ","9/")

oldDate = replace(oldDate,"October ","10/")

oldDate = replace(oldDate,"November ","11/")

oldDate = replace(oldDate,"December ","12/")

'''''''''''''''''''''''''''''''''''''17/6/2010 08:58:02
AM



datetemp = split(oldDate,"/")

newMonth = datetemp(1)

newDay = datetemp(0)

stuff = datetemp(2)



theNewDate = newMonth & "/" & newDay & "/" & stuff

'''''''''''''''''''''''''''''''''''''6/17/2010 08:58:02
AM



sql = "UPDATE TABLE1 SET employee_signed_on = '" &
theNewDate & "' WHERE id = " & id

   

Re: [PHP] Date Conversion Problem

2010-06-17 Thread Shreyas Agasthya
David,

I think it would help people like me (newbie) to know the exact statements.
Though I could envisage what you would have done with my current learning,
it would be good if I double check the statements that went there to fix
it.

Regards,
Shreyas

On Thu, Jun 17, 2010 at 7:07 PM, David Stoltz  wrote:

> Thanks all - I've fixed the problem.
>
> I fixed it by updating the php statement to write the date in a true SQL
> date-ready format. Then I updated the invalid rows.
>
> Thanks all!
>
>
> -Original Message-
> From: Richard Quadling [mailto:rquadl...@gmail.com]
> Sent: Thursday, June 17, 2010 8:47 AM
> To: David Stoltz
> Cc: a...@ashleysheridan.co.uk; php-general@lists.php.net
> Subject: Re: [PHP] Date Conversion Problem
>
> On 17 June 2010 13:40, David Stoltz  wrote:
> > I would agree with you, but I have no control on inherited web apps.
> >
> >
> >
> > I now need to concentrate on trying to fix this.
> >
> >
> >
> > From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> > Sent: Thursday, June 17, 2010 8:38 AM
> > To: David Stoltz
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] Date Conversion Problem
> >
> >
> >
> > On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote:
> >
> >
> > PHP newbie here...
> >
> >
> >
> > I have some PHP code writing the date/time into a MS SQL 2000 database
> > like this:
> >
> >
> >
> > date('l jS \of F Y h:i:s A')
> >
> >
> >
> > So the text it writes into the DB is like: Thursday 15th of April 2010
> > 10:13:42 AM
> >
> >
> >
> > The database field is defined as varchar, not datetime...so it's a
> > string essentially...
> >
> >
> >
> > How in the world do I do a date conversion on this? I've tried things
> > like:
> >
> >
> >
> > select * from table where convert(datetime,fieldname) >= '6/10/2010'
> >
> > (where fieldname is the string in question)
> >
> >
> >
> > Which results in "Syntax error converting datetime from character
> > string."
> >
> >
> >
> > So I guess I have two questions:
> >
> >
> >
> > 1)  Can I write a SQL query that will convert this properly into a
> > datetime?
> >
> > 2)  If not, I guess I'll need to change the code to write the date
> > differently into the system, how should this statement be changed to
> > allow for proper conversion? date('l jS \of F Y h:i:s A')
> >
> >
> >
> > Thanks for any help!
> >
> >
> >
> > It's best to store the date as a date rather than a string, as it avoids
> the sorts of problems you're seeing now.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> >
> >
> >
>
> The "fix" is most likely to be ...
>
> 1 - Convert the string date using PHP's strtotime() function to
> populate a new column on the DB.
> 2 - Find the code that inserts/updates the date string and add the new
> column to the insert/update statement.
>
> That will preserve the current app and allow you to have the new
> column for new work.
>
> Just remember, if _YOU_ update the new column, you must also update
> the original date string also.
>
> --
> -
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>



-- 
Regards,
Shreyas Agasthya


RE: [PHP] Date Conversion Problem

2010-06-17 Thread David Stoltz
Thanks all - I've fixed the problem.

I fixed it by updating the php statement to write the date in a true SQL 
date-ready format. Then I updated the invalid rows.

Thanks all!


-Original Message-
From: Richard Quadling [mailto:rquadl...@gmail.com] 
Sent: Thursday, June 17, 2010 8:47 AM
To: David Stoltz
Cc: a...@ashleysheridan.co.uk; php-general@lists.php.net
Subject: Re: [PHP] Date Conversion Problem

On 17 June 2010 13:40, David Stoltz  wrote:
> I would agree with you, but I have no control on inherited web apps.
>
>
>
> I now need to concentrate on trying to fix this.
>
>
>
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: Thursday, June 17, 2010 8:38 AM
> To: David Stoltz
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Date Conversion Problem
>
>
>
> On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote:
>
>
> PHP newbie here...
>
>
>
> I have some PHP code writing the date/time into a MS SQL 2000 database
> like this:
>
>
>
> date('l jS \of F Y h:i:s A')
>
>
>
> So the text it writes into the DB is like: Thursday 15th of April 2010
> 10:13:42 AM
>
>
>
> The database field is defined as varchar, not datetime...so it's a
> string essentially...
>
>
>
> How in the world do I do a date conversion on this? I've tried things
> like:
>
>
>
> select * from table where convert(datetime,fieldname) >= '6/10/2010'
>
> (where fieldname is the string in question)
>
>
>
> Which results in "Syntax error converting datetime from character
> string."
>
>
>
> So I guess I have two questions:
>
>
>
> 1)      Can I write a SQL query that will convert this properly into a
> datetime?
>
> 2)      If not, I guess I'll need to change the code to write the date
> differently into the system, how should this statement be changed to
> allow for proper conversion? date('l jS \of F Y h:i:s A')
>
>
>
> Thanks for any help!
>
>
>
> It's best to store the date as a date rather than a string, as it avoids the 
> sorts of problems you're seeing now.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
>

The "fix" is most likely to be ...

1 - Convert the string date using PHP's strtotime() function to
populate a new column on the DB.
2 - Find the code that inserts/updates the date string and add the new
column to the insert/update statement.

That will preserve the current app and allow you to have the new
column for new work.

Just remember, if _YOU_ update the new column, you must also update
the original date string also.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


RE: [PHP] Date Conversion Problem

2010-06-17 Thread David Stoltz
Here's my approach to this problem, and how I am planning on fixing this - tell 
me what you think if this will work...

I need the format in the database to be "1/14/2010 3:25:58 PM"

There's not a ton of records that need to be updated, so I was going to:

1) Change the PHP function that is writing the date format incorrectly to the 
above format
2) Then manually go through the records and update the incorrect dates
3) Then change the datatype in the DB for that column from varchar to datetime

Far as I can see, this should work. 

This is why I hate inheriting other people's stuff...not to mention I'm a 
newbie, so that doesn't help ;-)

Thanks!


-Original Message-
From: Richard Quadling [mailto:rquadl...@gmail.com] 
Sent: Thursday, June 17, 2010 8:47 AM
To: David Stoltz
Cc: a...@ashleysheridan.co.uk; php-general@lists.php.net
Subject: Re: [PHP] Date Conversion Problem

On 17 June 2010 13:40, David Stoltz  wrote:
> I would agree with you, but I have no control on inherited web apps.
>
>
>
> I now need to concentrate on trying to fix this.
>
>
>
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: Thursday, June 17, 2010 8:38 AM
> To: David Stoltz
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Date Conversion Problem
>
>
>
> On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote:
>
>
> PHP newbie here...
>
>
>
> I have some PHP code writing the date/time into a MS SQL 2000 database
> like this:
>
>
>
> date('l jS \of F Y h:i:s A')
>
>
>
> So the text it writes into the DB is like: Thursday 15th of April 2010
> 10:13:42 AM
>
>
>
> The database field is defined as varchar, not datetime...so it's a
> string essentially...
>
>
>
> How in the world do I do a date conversion on this? I've tried things
> like:
>
>
>
> select * from table where convert(datetime,fieldname) >= '6/10/2010'
>
> (where fieldname is the string in question)
>
>
>
> Which results in "Syntax error converting datetime from character
> string."
>
>
>
> So I guess I have two questions:
>
>
>
> 1)      Can I write a SQL query that will convert this properly into a
> datetime?
>
> 2)      If not, I guess I'll need to change the code to write the date
> differently into the system, how should this statement be changed to
> allow for proper conversion? date('l jS \of F Y h:i:s A')
>
>
>
> Thanks for any help!
>
>
>
> It's best to store the date as a date rather than a string, as it avoids the 
> sorts of problems you're seeing now.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
>

The "fix" is most likely to be ...

1 - Convert the string date using PHP's strtotime() function to
populate a new column on the DB.
2 - Find the code that inserts/updates the date string and add the new
column to the insert/update statement.

That will preserve the current app and allow you to have the new
column for new work.

Just remember, if _YOU_ update the new column, you must also update
the original date string also.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


Re: [PHP] Date Conversion Problem

2010-06-17 Thread Richard Quadling
On 17 June 2010 13:40, David Stoltz  wrote:
> I would agree with you, but I have no control on inherited web apps.
>
>
>
> I now need to concentrate on trying to fix this.
>
>
>
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: Thursday, June 17, 2010 8:38 AM
> To: David Stoltz
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Date Conversion Problem
>
>
>
> On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote:
>
>
> PHP newbie here...
>
>
>
> I have some PHP code writing the date/time into a MS SQL 2000 database
> like this:
>
>
>
> date('l jS \of F Y h:i:s A')
>
>
>
> So the text it writes into the DB is like: Thursday 15th of April 2010
> 10:13:42 AM
>
>
>
> The database field is defined as varchar, not datetime...so it's a
> string essentially...
>
>
>
> How in the world do I do a date conversion on this? I've tried things
> like:
>
>
>
> select * from table where convert(datetime,fieldname) >= '6/10/2010'
>
> (where fieldname is the string in question)
>
>
>
> Which results in "Syntax error converting datetime from character
> string."
>
>
>
> So I guess I have two questions:
>
>
>
> 1)      Can I write a SQL query that will convert this properly into a
> datetime?
>
> 2)      If not, I guess I'll need to change the code to write the date
> differently into the system, how should this statement be changed to
> allow for proper conversion? date('l jS \of F Y h:i:s A')
>
>
>
> Thanks for any help!
>
>
>
> It's best to store the date as a date rather than a string, as it avoids the 
> sorts of problems you're seeing now.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
>

The "fix" is most likely to be ...

1 - Convert the string date using PHP's strtotime() function to
populate a new column on the DB.
2 - Find the code that inserts/updates the date string and add the new
column to the insert/update statement.

That will preserve the current app and allow you to have the new
column for new work.

Just remember, if _YOU_ update the new column, you must also update
the original date string also.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Conversion Problem

2010-06-17 Thread Richard Quadling
On 17 June 2010 13:40, Richard Quadling  wrote:
> On 17 June 2010 13:35, David Stoltz  wrote:
>> PHP newbie here...
>>
>>
>>
>> I have some PHP code writing the date/time into a MS SQL 2000 database
>> like this:
>>
>>
>>
>> date('l jS \of F Y h:i:s A')
>>
>>
>>
>> So the text it writes into the DB is like: Thursday 15th of April 2010
>> 10:13:42 AM
>>
>>
>>
>> The database field is defined as varchar, not datetime...so it's a
>> string essentially...
>>
>>
>>
>> How in the world do I do a date conversion on this? I've tried things
>> like:
>>
>>
>>
>> select * from table where convert(datetime,fieldname) >= '6/10/2010'
>>
>> (where fieldname is the string in question)
>>
>>
>>
>> Which results in "Syntax error converting datetime from character
>> string."
>>
>>
>>
>> So I guess I have two questions:
>>
>>
>>
>> 1)      Can I write a SQL query that will convert this properly into a
>> datetime?
>>
>> 2)      If not, I guess I'll need to change the code to write the date
>> differently into the system, how should this statement be changed to
>> allow for proper conversion? date('l jS \of F Y h:i:s A')
>>
>>
>>
>> Thanks for any help!
>>
>>
>
> Under normal conditions, you would store the date in a datetime
> column. That allows you to do all the date range work in the DB.
>
> When you display the date, you would use PHP's date() function for
> format it appropriately.
>
>
> date('l jS \of F Y h:i:s A', $row['fieldname']);
>
> sort of thing.
>
> --
> -
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>


Having said that, you will have some serious issues is your dates are
generated from around the world and not purely in your local timezone.

A lack of timezone (Europe/London, Europe/Berlin) rather than the
timezone offset (+1:00, etc.) is the issue here.

Due to DST changes not being consistent worldwide, with the timezones
changing over time, etc. All quite complicated.




-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Conversion Problem

2010-06-17 Thread Richard Quadling
On 17 June 2010 13:35, David Stoltz  wrote:
> PHP newbie here...
>
>
>
> I have some PHP code writing the date/time into a MS SQL 2000 database
> like this:
>
>
>
> date('l jS \of F Y h:i:s A')
>
>
>
> So the text it writes into the DB is like: Thursday 15th of April 2010
> 10:13:42 AM
>
>
>
> The database field is defined as varchar, not datetime...so it's a
> string essentially...
>
>
>
> How in the world do I do a date conversion on this? I've tried things
> like:
>
>
>
> select * from table where convert(datetime,fieldname) >= '6/10/2010'
>
> (where fieldname is the string in question)
>
>
>
> Which results in "Syntax error converting datetime from character
> string."
>
>
>
> So I guess I have two questions:
>
>
>
> 1)      Can I write a SQL query that will convert this properly into a
> datetime?
>
> 2)      If not, I guess I'll need to change the code to write the date
> differently into the system, how should this statement be changed to
> allow for proper conversion? date('l jS \of F Y h:i:s A')
>
>
>
> Thanks for any help!
>
>

Under normal conditions, you would store the date in a datetime
column. That allows you to do all the date range work in the DB.

When you display the date, you would use PHP's date() function for
format it appropriately.


date('l jS \of F Y h:i:s A', $row['fieldname']);

sort of thing.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date Conversion Problem

2010-06-17 Thread David Stoltz
I would agree with you, but I have no control on inherited web apps.

 

I now need to concentrate on trying to fix this.

 

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Thursday, June 17, 2010 8:38 AM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Date Conversion Problem

 

On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote: 

 
PHP newbie here...
 
 
 
I have some PHP code writing the date/time into a MS SQL 2000 database
like this:
 
 
 
date('l jS \of F Y h:i:s A')
 
 
 
So the text it writes into the DB is like: Thursday 15th of April 2010
10:13:42 AM
 
 
 
The database field is defined as varchar, not datetime...so it's a
string essentially...
 
 
 
How in the world do I do a date conversion on this? I've tried things
like:
 
 
 
select * from table where convert(datetime,fieldname) >= '6/10/2010' 
 
(where fieldname is the string in question)
 
 
 
Which results in "Syntax error converting datetime from character
string."
 
 
 
So I guess I have two questions:
 
 
 
1)  Can I write a SQL query that will convert this properly into a
datetime?
 
2)  If not, I guess I'll need to change the code to write the date
differently into the system, how should this statement be changed to
allow for proper conversion? date('l jS \of F Y h:i:s A')
 
 
 
Thanks for any help!
 


It's best to store the date as a date rather than a string, as it avoids the 
sorts of problems you're seeing now.

Thanks,
Ash
http://www.ashleysheridan.co.uk



 



Re: [PHP] Date Conversion Problem

2010-06-17 Thread Ashley Sheridan
On Thu, 2010-06-17 at 08:35 -0400, David Stoltz wrote:

> PHP newbie here...
> 
>  
> 
> I have some PHP code writing the date/time into a MS SQL 2000 database
> like this:
> 
>  
> 
> date('l jS \of F Y h:i:s A')
> 
>  
> 
> So the text it writes into the DB is like: Thursday 15th of April 2010
> 10:13:42 AM
> 
>  
> 
> The database field is defined as varchar, not datetime...so it's a
> string essentially...
> 
>  
> 
> How in the world do I do a date conversion on this? I've tried things
> like:
> 
>  
> 
> select * from table where convert(datetime,fieldname) >= '6/10/2010' 
> 
> (where fieldname is the string in question)
> 
>  
> 
> Which results in "Syntax error converting datetime from character
> string."
> 
>  
> 
> So I guess I have two questions:
> 
>  
> 
> 1)  Can I write a SQL query that will convert this properly into a
> datetime?
> 
> 2)  If not, I guess I'll need to change the code to write the date
> differently into the system, how should this statement be changed to
> allow for proper conversion? date('l jS \of F Y h:i:s A')
> 
>  
> 
> Thanks for any help!
> 


It's best to store the date as a date rather than a string, as it avoids
the sorts of problems you're seeing now.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Date Conversion Problem

2010-06-17 Thread David Stoltz
PHP newbie here...

 

I have some PHP code writing the date/time into a MS SQL 2000 database
like this:

 

date('l jS \of F Y h:i:s A')

 

So the text it writes into the DB is like: Thursday 15th of April 2010
10:13:42 AM

 

The database field is defined as varchar, not datetime...so it's a
string essentially...

 

How in the world do I do a date conversion on this? I've tried things
like:

 

select * from table where convert(datetime,fieldname) >= '6/10/2010' 

(where fieldname is the string in question)

 

Which results in "Syntax error converting datetime from character
string."

 

So I guess I have two questions:

 

1)  Can I write a SQL query that will convert this properly into a
datetime?

2)  If not, I guess I'll need to change the code to write the date
differently into the system, how should this statement be changed to
allow for proper conversion? date('l jS \of F Y h:i:s A')

 

Thanks for any help!



Re: [PHP] Date Math

2010-04-21 Thread Floyd Resler

On Apr 21, 2010, at 5:39 AM, Michiel Sikma wrote:

> On 20 April 2010 17:40, Floyd Resler  wrote:
> 
>> I need to get the difference in months between two dates.  The dates could
>> be as much as 60 months apart.  Is there any easy way to do this either
>> through PHP or MySQL?  I know how I can do it through code but thought there
>> might be a simple one or two line option.
>> 
>> Thanks!
>> Floyd
>> 
>> 
> You're best off doing this in MySQL.
> Something like select timestampdiff(month, '2010-01-01', '2010-05-22');
> should work.
> 
> Michiel

Perfect!  That's exactly what I was looking for!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Math

2010-04-21 Thread Michiel Sikma
On 20 April 2010 17:40, Floyd Resler  wrote:

> I need to get the difference in months between two dates.  The dates could
> be as much as 60 months apart.  Is there any easy way to do this either
> through PHP or MySQL?  I know how I can do it through code but thought there
> might be a simple one or two line option.
>
> Thanks!
> Floyd
>
>
You're best off doing this in MySQL.
Something like select timestampdiff(month, '2010-01-01', '2010-05-22');
should work.

Michiel


Re: [PHP] Date Math

2010-04-20 Thread Paul M Foster
On Tue, Apr 20, 2010 at 03:32:58PM -0400, tedd wrote:

> At 11:40 AM -0400 4/20/10, Floyd Resler wrote:
>> I need to get the difference in months between two dates.  The dates
>> could be as much as 60 months apart.  Is there any easy way to do
>> this either through PHP or MySQL?  I know how I can do it through
>> code but thought there might be a simple one or two line option.
>>
>> Thanks!
>> Floyd
>>
>
>
> 
> $date1 = '2009-02-27';
> $date2 = '2004-12-03';
>
> $udate1 = strtotime($date1);
> $udate2 = strtotime($date2);

$from = getdate($udate1);
$from_year = $from['year'];
$from_month = $from['month'];

$to = getdate($udate2);
$to_year = $to['year'];
$to_month = $to['month'];

// Assumes $to_date is later than $from_date

if ($from_year == $to_year)
$months = $to_month - $from_month;
elseif ($to_month >= $from_month) {
$num_years = $to_year - $from_year;
$add_months = $num_years * 12;
$base_months = $to_month - $from_month;
$months = $base_months + $add_months;
}
else { // $to_month < $from_month
$num_years = $to_year - $from_year;
$base_months = $num_years * 12;
$sub_months = $from_month - $to_month;
$months = $base_months - $sub_months;
}

This will give the months between two dates, ignoring the actual day of
the month for each date (may not be exactly what you want, and code is
untested).

>
> $difference = $udate1 - $udate2;
>
> $months_difference = floor($difference / 2678400);
>
> echo("The difference is $months_difference months");
>
> ?>
>
> I this will work, but the question of what constitutes a month might
> come into play.

My code above is submitted because I don't like doing calculations with
seconds. Tedd's right, the OP's questions can't be answered precisely
because months vary in number of days.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Math

2010-04-20 Thread tedd

At 11:40 AM -0400 4/20/10, Floyd Resler wrote:
I need to get the difference in months between two dates.  The dates 
could be as much as 60 months apart.  Is there any easy way to do 
this either through PHP or MySQL?  I know how I can do it through 
code but thought there might be a simple one or two line option.


Thanks!
Floyd






I this will work, but the question of what constitutes a month might 
come into play.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Math

2010-04-20 Thread Dan Joseph
On Tue, Apr 20, 2010 at 11:40 AM, Floyd Resler wrote:

> I need to get the difference in months between two dates.  The dates could
> be as much as 60 months apart.  Is there any easy way to do this either
> through PHP or MySQL?  I know how I can do it through code but thought there
> might be a simple one or two line option.
>
>
check out:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

-- 
-Dan Joseph

www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
Code "NEWTHINGS" for 10% off initial order

http://www.facebook.com/canishosting
http://www.facebook.com/originalpoetry


[PHP] Date Math

2010-04-20 Thread Floyd Resler
I need to get the difference in months between two dates.  The dates could be 
as much as 60 months apart.  Is there any easy way to do this either through 
PHP or MySQL?  I know how I can do it through code but thought there might be a 
simple one or two line option.

Thanks!
Floyd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: intermittent failure of php date

2010-01-18 Thread Ashley Sheridan
On Mon, 2010-01-18 at 10:32 -0500, John Corry wrote:

> The field in the DB is defined as type date.
> 
> I've had several event registrations for an upcoming event come through. THe
> event date is '2010-01-27'.
> 
> 2 of the 5 event registrations contained empty values for the date.
> 
> wtf?
> 
> On Mon, Jan 18, 2010 at 10:23 AM, John Corry  wrote:
> 
> > I maintain a site that is generating some strange behavior...
> >
> > It's a custom built event registration app.
> >
> > Events have event_dates that are stored in the MySQL db.
> >
> > This code retrieves the event title and event date for display on the
> > registration acknowledgment page:
> >
> > $q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
> > formatted_event_date FROM events WHERE id =" . $eid . ";";
> >  $result = mysql_query($q2);
> >  if ($result) {
> >$row = mysql_fetch_array($result);
> >$title = $row['title'];
> >
> >if(strtotime($row['event_date'])) {
> >   $event_date = date("F m, Y", strtotime($row['event_date']));
> >} else {
> >   $event_date = $row['formatted_event_date'];
> >}
> >
> > Sometimes, it doesn't work.
> >
> > Every 3rd or 4th registration notification email comes through with an
> > empty value for event_date.
> >
> > There are no other references to the variable $event_date.
> >
> > It works most of the time.
> >
> > There's no pattern I can see. I even tried to force it to show a date by
> > selecting a formatted date and displaying that if the original programmer's
> > strtotime failed.
> >
> > Where do you look for help with intermittent failures of a date field in
> > the DB?
> >
> >
> > --
> > John Corry
> > PHP developer - 3by400, Inc
> > http://www.3by400.com
> >
> >
> 
> 


This sounds more like a problem with the code that is inserting the data
than the code that is retrieving it. A database should just lose data
randomly from fields unless you've got a really serious problem with
your computer system.

Are you sanitising the data that is being entered by people on the site?
If you don't force them to enter a date, then they might not enter one
at all, leading a null value or empty string to be entered into the date
field instead of a valid date.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: intermittent failure of php date

2010-01-18 Thread John Corry
The field in the DB is defined as type date.

I've had several event registrations for an upcoming event come through. THe
event date is '2010-01-27'.

2 of the 5 event registrations contained empty values for the date.

wtf?

On Mon, Jan 18, 2010 at 10:23 AM, John Corry  wrote:

> I maintain a site that is generating some strange behavior...
>
> It's a custom built event registration app.
>
> Events have event_dates that are stored in the MySQL db.
>
> This code retrieves the event title and event date for display on the
> registration acknowledgment page:
>
> $q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
> formatted_event_date FROM events WHERE id =" . $eid . ";";
>  $result = mysql_query($q2);
>  if ($result) {
>$row = mysql_fetch_array($result);
>$title = $row['title'];
>
>if(strtotime($row['event_date'])) {
>   $event_date = date("F m, Y", strtotime($row['event_date']));
>} else {
>   $event_date = $row['formatted_event_date'];
>}
>
> Sometimes, it doesn't work.
>
> Every 3rd or 4th registration notification email comes through with an
> empty value for event_date.
>
> There are no other references to the variable $event_date.
>
> It works most of the time.
>
> There's no pattern I can see. I even tried to force it to show a date by
> selecting a formatted date and displaying that if the original programmer's
> strtotime failed.
>
> Where do you look for help with intermittent failures of a date field in
> the DB?
>
>
> --
> John Corry
> PHP developer - 3by400, Inc
> http://www.3by400.com
>
>


-- 
John Corry
PHP developer - 3by400, Inc
http://www.3by400.com


[PHP] intermittent failure of php date

2010-01-18 Thread John Corry
I maintain a site that is generating some strange behavior...

It's a custom built event registration app.

Events have event_dates that are stored in the MySQL db.

This code retrieves the event title and event date for display on the
registration acknowledgment page:

$q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
formatted_event_date FROM events WHERE id =" . $eid . ";";
 $result = mysql_query($q2);
 if ($result) {
   $row = mysql_fetch_array($result);
   $title = $row['title'];

   if(strtotime($row['event_date'])) {
  $event_date = date("F m, Y", strtotime($row['event_date']));
   } else {
  $event_date = $row['formatted_event_date'];
   }

Sometimes, it doesn't work.

Every 3rd or 4th registration notification email comes through with an empty
value for event_date.

There are no other references to the variable $event_date.

It works most of the time.

There's no pattern I can see. I even tried to force it to show a date by
selecting a formatted date and displaying that if the original programmer's
strtotime failed.

Where do you look for help with intermittent failures of a date field in the
DB?


-- 
John Corry
PHP developer - 3by400, Inc
http://www.3by400.com


Re: [PHP] Date Comparison

2009-09-03 Thread tedd

At 10:01 AM +0200 9/3/09, J DeBord wrote:

Telling someone RTFM is just rude and mean.


And not taking the time to research your question before posting is 
what, thoughtful and kind?


The phrase RTFM is something I don't like to tell people, and from 
what I remember, I have never said that to anyone. However I can 
understand where one could read a person's question and deduce that 
they did NO research for themselves. Instead, they posted their 
question for others to do their research for them because they were 
too lazy to do it themselves. No matter how you cut that, that's 
lame. So, I certainly don't blame anyone for telling such a person to 
RTFM.



 I would suggest
that when a question asked here causes you to respond with RTFM, don't
respond at all. Save yourself the time and trouble and save the person
asking the question the grief of being insulted.


Well that's your prerogative to do as you want. But it's a bit 
arrogant of you to tell others how to conduct themselves on this 
list, don't you think? Who made you list monitor?




And Tedd your condescending
response caused me to lose respect for you.


No offense, but let me make this perfectly clear -- I don't give a 
rat's ass what you think about me. From my perspective, you could win 
the lottery or die tomorrow, it makes no difference to me either way.


I'm not here to win/lose your respect. I'm here to help those who ask 
honest questions. I, like many others, simply donate our time freely 
without any benefit whatsoever. If you have problems with that, then 
you probably have bigger problems elsewhere.




I'm sure the OP would have been
more than thankful to receive the same response without the RTFM. I'll read
any response to this, but I won't have anything more to say. This list has
been polluted enough lately with nonsense. Incredible.


What's Incredible is how people can post to this list thinking that 
they have some right to post whatever they want and expect others to 
comment as they want. And, if they don't get what they want, then 
they whine about the list being rude and mean. That's Incredible.


My advice, if you have problems with this list, get over it! There's 
much more in this world to get upset about rather than what happens 
on this list.


tedd

---




On Sat, Aug 29, 2009 at 3:44 PM, tedd  wrote:


 At 1:01 PM -0400 8/28/09, David Stoltz wrote:


 Hey Stuart -

 RTFM yourselfI did read it, and obviously misunderstood...

 I'm really sorry to bother you. I thought that was what a listserv like
 this was for - to ask questions...

 I'll try not to ask questions I should know the answer to next time.



 Whoa dude!

 You just received advice from a brilliant man and you are bitching about
 it?!?

 Look child, you are being told what you should do by a professional who is
 donating his time freely to help you. Just how did you not understand that?

 So, just do what he advised and say "Thank you sir, may I have another?"

 I've posted some dumb-ass questions before, but only after I took the time
 to research the question myself. And when someone took the time to
 straighten me out and help, I appreciated it.

 Hopefully next time you'll read the manual and take the time to understand
 what you read -- it would cut down on post that demonstrate just how
 ignorant and thankless you are at this.

 Cheers,

 tedd

 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Comparison

2009-09-03 Thread Paul M Foster
On Thu, Sep 03, 2009 at 10:20:49AM +0100, Stuart wrote:

> 2009/9/3 J DeBord :
> > Telling someone RTFM is just rude and mean. Manipulating dates and times can
> > be confusing for beginners and experienced people alike. I would suggest
> > that when a question asked here causes you to respond with RTFM, don't
> > respond at all. Save yourself the time and trouble and save the person
> > asking the question the grief of being insulted. And Tedd your condescending
> > response caused me to lose respect for you. I'm sure the OP would have been
> > more than thankful to receive the same response without the RTFM. I'll read
> > any response to this, but I won't have anything more to say. This list has
> > been polluted enough lately with nonsense. Incredible.
> 
> You're entitled to your opinion as much as I am, and my opinion is
> that not making it clear to people that the answer to their question
> is plainly obvious in the manual is just as rude if not more so than
> suggesting they RTFM.
> 
> I make a point to never just say RTFM but to also answer the question
> at the same time, but IMHO not telling people how fundamental their
> question was does not help them in the long run. At the end of the day
> it just encourages them to continue to rely on this list rather than
> learning how to find the answer themselves and to only use this list
> as a last resort.
> 
> I make no apology for my attitude towards this type of question, and
> if you don't like it you can stick it where the sun don't shine.

+1

I can't argue with this approach. If you're going to point the poster to
the manual and *then* explain, that's the ideal way to do this. Now it
could be argued that you could say, "Please refer to
http://php.net/manual/en/whatever.php for more info." Or you could say,
"RTFM". The former is more polite, but the latter will suffice. Both
mean the same thing; one is simply more terse.

Also stipulated that one should research a question as much as possible
before posting to this list. We're not tutors; more like professional
side-checkers.

(Please don't take this the wrong way, newbies. You're welcome to ask
questions here. Just do whatever research you can first, and follow our
advice afterward, to RTFM.)

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Comparison

2009-09-03 Thread Stuart
2009/9/3 J DeBord :
> Telling someone RTFM is just rude and mean. Manipulating dates and times can
> be confusing for beginners and experienced people alike. I would suggest
> that when a question asked here causes you to respond with RTFM, don't
> respond at all. Save yourself the time and trouble and save the person
> asking the question the grief of being insulted. And Tedd your condescending
> response caused me to lose respect for you. I'm sure the OP would have been
> more than thankful to receive the same response without the RTFM. I'll read
> any response to this, but I won't have anything more to say. This list has
> been polluted enough lately with nonsense. Incredible.

You're entitled to your opinion as much as I am, and my opinion is
that not making it clear to people that the answer to their question
is plainly obvious in the manual is just as rude if not more so than
suggesting they RTFM.

I make a point to never just say RTFM but to also answer the question
at the same time, but IMHO not telling people how fundamental their
question was does not help them in the long run. At the end of the day
it just encourages them to continue to rely on this list rather than
learning how to find the answer themselves and to only use this list
as a last resort.

I make no apology for my attitude towards this type of question, and
if you don't like it you can stick it where the sun don't shine.

-Stuart

-- 
http://stut.net/

> On Sat, Aug 29, 2009 at 3:44 PM, tedd  wrote:
>
>> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>>
>>> Hey Stuart -
>>>
>>> RTFM yourselfI did read it, and obviously misunderstood...
>>>
>>> I'm really sorry to bother you. I thought that was what a listserv like
>>> this was for - to ask questions...
>>>
>>> I'll try not to ask questions I should know the answer to next time.
>>>
>>
>> Whoa dude!
>>
>> You just received advice from a brilliant man and you are bitching about
>> it?!?
>>
>> Look child, you are being told what you should do by a professional who is
>> donating his time freely to help you. Just how did you not understand that?
>>
>> So, just do what he advised and say "Thank you sir, may I have another?"
>>
>> I've posted some dumb-ass questions before, but only after I took the time
>> to research the question myself. And when someone took the time to
>> straighten me out and help, I appreciated it.
>>
>> Hopefully next time you'll read the manual and take the time to understand
>> what you read -- it would cut down on post that demonstrate just how
>> ignorant and thankless you are at this.
>>
>> Cheers,
>>
>> tedd
>>
>> --
>> ---
>> http://sperling.com  http://ancientstones.com  http://earthstones.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date Comparison

2009-09-03 Thread J DeBord
Telling someone RTFM is just rude and mean. Manipulating dates and times can
be confusing for beginners and experienced people alike. I would suggest
that when a question asked here causes you to respond with RTFM, don't
respond at all. Save yourself the time and trouble and save the person
asking the question the grief of being insulted. And Tedd your condescending
response caused me to lose respect for you. I'm sure the OP would have been
more than thankful to receive the same response without the RTFM. I'll read
any response to this, but I won't have anything more to say. This list has
been polluted enough lately with nonsense. Incredible.


On Sat, Aug 29, 2009 at 3:44 PM, tedd  wrote:

> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>
>> Hey Stuart -
>>
>> RTFM yourselfI did read it, and obviously misunderstood...
>>
>> I'm really sorry to bother you. I thought that was what a listserv like
>> this was for - to ask questions...
>>
>> I'll try not to ask questions I should know the answer to next time.
>>
>
> Whoa dude!
>
> You just received advice from a brilliant man and you are bitching about
> it?!?
>
> Look child, you are being told what you should do by a professional who is
> donating his time freely to help you. Just how did you not understand that?
>
> So, just do what he advised and say "Thank you sir, may I have another?"
>
> I've posted some dumb-ass questions before, but only after I took the time
> to research the question myself. And when someone took the time to
> straighten me out and help, I appreciated it.
>
> Hopefully next time you'll read the manual and take the time to understand
> what you read -- it would cut down on post that demonstrate just how
> ignorant and thankless you are at this.
>
> Cheers,
>
> tedd
>
> --
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


RE: [PHP] Date +30 comparison

2009-09-02 Thread tedd

At 4:06 PM +0100 9/2/09, Ford, Mike wrote:

 > -Original Message-

 From: tedd [mailto:tedd.sperl...@gmail.com]
 Sent: 01 September 2009 21:52

 At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
 >On Tue, Sep 1, 2009 at 1:27 PM, tedd
 wrote:
 >>  First get the date to seconds, like so:
 >>
 >>  $today_date = '8/26/2009';
 >>
 >>  $next_date = strtotime($today_date) + (86400 * 30);
 >>
 >
 >No. Due to Daylight Saving Time, many time zones have two days each
 >year when the number of seconds in a day is not 86400.
 >

 Arrggg.

 But good to know.


And if you absolutely insist on doing it this way, make sure you 
start in the middle of the day -- if your base time is 12:00 noon 
(which is what I always use in this situation), the furthest it can 
go because of DST is 11:00 or 13:00, which won't screw you up if all 
you're interested in is the date. ;)



Cheers!

Mike


Another good thing to know.

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date +30 comparison

2009-09-02 Thread Ford, Mike
> -Original Message-
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 01 September 2009 21:52
> 
> At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
> >On Tue, Sep 1, 2009 at 1:27 PM, tedd
> wrote:
> >>  First get the date to seconds, like so:
> >>
> >>  $today_date = '8/26/2009';
> >>
> >>  $next_date = strtotime($today_date) + (86400 * 30);
> >>
> >
> >No. Due to Daylight Saving Time, many time zones have two days each
> >year when the number of seconds in a day is not 86400.
> >
> 
> Arrggg.
> 
> But good to know.

And if you absolutely insist on doing it this way, make sure you start in the 
middle of the day -- if your base time is 12:00 noon (which is what I always 
use in this situation), the furthest it can go because of DST is 11:00 or 
13:00, which won't screw you up if all you're interested in is the date. ;)


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread tedd

At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:

On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:

 First get the date to seconds, like so:

 $today_date = '8/26/2009';

 $next_date = strtotime($today_date) + (86400 * 30);



No. Due to Daylight Saving Time, many time zones have two days each
year when the number of seconds in a day is not 86400.



Arrggg.

But good to know.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread Paul M Foster
On Tue, Sep 01, 2009 at 02:47:43PM -0400, Andrew Ballard wrote:

> On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:
> > First get the date to seconds, like so:
> >
> > $today_date = '8/26/2009';
> >
> > $next_date = strtotime($today_date) + (86400 * 30);
> >
> 
> No. Due to Daylight Saving Time, many time zones have two days each
> year when the number of seconds in a day is not 86400.

This and the "2038" bug are reasons to do this type of calculation with
Julian days, as opposed to seconds.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread Andrew Ballard
On Tue, Sep 1, 2009 at 1:27 PM, tedd wrote:
> First get the date to seconds, like so:
>
> $today_date = '8/26/2009';
>
> $next_date = strtotime($today_date) + (86400 * 30);
>

No. Due to Daylight Saving Time, many time zones have two days each
year when the number of seconds in a day is not 86400.

> OR
>
> $next_date  = strtotime('+30 days', strtotime($today_date));
>
> Then take the seconds back to a date, like so:
>
> $the_date = date('m/d/Y', $next_date);

Yes.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date +30 comparison

2009-09-01 Thread tedd

At 1:28 PM -0400 9/1/09, David Stoltz wrote:

Ok, this is how I finally managed to get it to work - I'm sure there are
other ways, but this works:

//Check to make sure the next eval date is more than 30 days away

$d1 = date('Y-m-d', strtotime($todays_date . '+30 day'));
$d2 = date('Y-m-d', strtotime($nextdate));

if($d1>$d2){

echo "Sorry, your next evaluation date must be at least 30 days
away, Click BACK to continue.";
exit;


You got it.

Just transform any date to seconds and then compare those seconds to 
other seconds (taken from other dates) and evaluate. Dead simple.


Also note that the strtotime() and date() combination provides some 
very nice features like keeping track of the resultant date. You 
don't have to worry about leap years, or months having 28-31 days, or 
anything like that -- it's all taken care of for you, pretty neat huh?


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date +30 comparison

2009-09-01 Thread David Stoltz
Ok, this is how I finally managed to get it to work - I'm sure there are
other ways, but this works:

//Check to make sure the next eval date is more than 30 days away

$d1 = date('Y-m-d', strtotime($todays_date . '+30 day'));
$d2 = date('Y-m-d', strtotime($nextdate));

if($d1>$d2){

echo "Sorry, your next evaluation date must be at least 30 days
away, Click BACK to continue.";
exit;

}


-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Tuesday, September 01, 2009 12:43 PM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Date +30 comparison

On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
> 
> Can someone provide code that does this:
> 
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
> 
> The variable $nexteval must be greater than $today (which is today +
30
> days) or a message is echoed.
> 
> I'm finding this difficult to do, but I'm coming from an ASP
background.
> 
> Any help appreciated.
> 

PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread tedd

At 5:43 PM +0100 9/1/09, Ashley Sheridan wrote:

On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:

 I'm really struggling with dates in PHP. (Yes, I tried reading the
 manual)...

 Can someone provide code that does this:

 Takes current date, assigns it to a variable (let's say $today)
 Then adds 30 days to $today variable
 Takes a string ($nexteval) like '8/26/2009' and compare it to $today.


 > The variable $nexteval must be greater than $today (which is today + 30

 days) or a message is echoed.

 I'm finding this difficult to do, but I'm coming from an ASP background.

 >
 > Any help appreciated.




PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.


David :

First get the date to seconds, like so:

$today_date = '8/26/2009';

$next_date = strtotime($today_date) + (86400 * 30);

OR

$next_date  = strtotime('+30 days', strtotime($today_date));

Then take the seconds back to a date, like so:

$the_date = date('m/d/Y', $next_date);

Here's the example:

http://www.webbytedd.com//future-date/

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread kranthi
i prefer http://in3.php.net/strtotime it supports loads of other
formats as well (including +30 days and 8/26/2009)
above all it returns unix time stamp which can be used directly with date().

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date +30 comparison

2009-09-01 Thread Dan Shirah
>
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
>
> Can someone provide code that does this:
>
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
>
> The variable $nexteval must be greater than $today (which is today + 30
> days) or a message is echoed.
>
> I'm finding this difficult to do, but I'm coming from an ASP background.
>
> Any help appreciated.
>
David,

Look up date() and mktime() in the manual.

To get today's date is easy: date('m/d/Y');

But when wanting to add days/months/years to a date, you need to use
mktime()

mktime() breaks apart a date into hours/minutes/seconds/months/days/years.

Therefore I always break up my date into these types fo sections.

$month = date('m');
$day = date('d');
$year = date('Y');

Now that I have them seperated I create a variable $future_date and assign
it the value I want. In your case, 30 days in the future.

$future_date = mktime(0,0,0,date($month),date($day)+30,date($year));

Now I put it back into a date format.

$future_date = date('m/d/Y',$future_date);

echo $future_date;

Today is September 1st and the value of $future_date is October 1st because
there are 30 days in Spetember.

Now you can compare your dates.

if ($nexteval > $future_date) {
  echo "This date has already passed";
} else {
  *do some processing*
}

Hope that helps.

Dan


Re: [PHP] Date +30 comparison

2009-09-01 Thread Ashley Sheridan
On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
> 
> Can someone provide code that does this:
> 
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
> 
> The variable $nexteval must be greater than $today (which is today + 30
> days) or a message is echoed.
> 
> I'm finding this difficult to do, but I'm coming from an ASP background.
> 
> Any help appreciated.
> 

PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   4   5   6   7   8   9   10   >