[PHP] Date problems

2007-01-04 Thread Beauford
Hi All,

I have a database with a bunch of dates in it. I want to count the number of
entries for each year and then display the year and the count.

i.e.

YearCount
200622
200518
200414
200322

This is what I have tried but just not quite getting it.

$query select count(date) as count, YEAR(date) as thisyear from stats group
by thisyear;

This is the error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in
C:\Websites\Website\test.php on line 29

So obviously I must have the syntax not quite right. If I run just select
YEAR(date) from stats from the mysql command line it works fine, so I
believe the database is set up right.

Any help is appreciated.

B

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



Re: [PHP] Date problems

2007-01-04 Thread Stut

Beauford wrote:

$query select count(date) as count, YEAR(date) as thisyear from stats group

^ = needed here

by thisyear;


-Stut

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



RE: [PHP] Date problems

2007-01-04 Thread Beauford
Yea, I just figured this out. When I cut and pasted I must have overwrote
the =.

Thanks
 

 -Original Message-
 From: Stut [mailto:[EMAIL PROTECTED] 
 Sent: January 4, 2007 4:27 PM
 To: Beauford
 Cc: PHP
 Subject: Re: [PHP] Date problems
 
 Beauford wrote:
  $query select count(date) as count, YEAR(date) as thisyear 
 from stats 
  group
  ^ = needed here
  by thisyear;
 
 -Stut
 
 

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



Re: [PHP] Date problems

2006-04-09 Thread Satyam
Timestamps are stored as seconds from a certain date.  The base date differ 
depending on the platform, Windows use 1/1/1980 the rest 1/1/1970, but still 
seconds.  7 days are 7*24*60*60.  Just add that much to a timestamp.  It 
helps having a constant such as:


define ('DAY_IN_SECONDS',86400);

Satyam


- Original Message - 
From: Mace Eliason [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Sunday, April 09, 2006 4:14 AM
Subject: [PHP] Date problems



Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with but it 
doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the $nextweek 
be different?


Thanks for the help

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

2006-04-09 Thread Rasmus Lerdorf

Satyam wrote:
Timestamps are stored as seconds from a certain date.  The base date 
differ depending on the platform, Windows use 1/1/1980 the rest 
1/1/1970, but still seconds.  7 days are 7*24*60*60.  Just add that much 
to a timestamp.  It helps having a constant such as:


define ('DAY_IN_SECONDS',86400);


The problem with doing it this way is that it won't take leap seconds, 
leap years and daylight savings into account, so on any of these edge 
cases it will appear to be broken.  That's why strtotime(+7 days) is 
the correct way to do this.


-Rasmus

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



[PHP] Date problems

2006-04-08 Thread Mace Eliason

Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with but 
it doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the $nextweek 
be different?


Thanks for the help

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



Re: [PHP] Date problems

2006-04-08 Thread Rasmus Lerdorf

Mace Eliason wrote:

Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with but 
it doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the $nextweek 
be different?


You are thinking too much!  ;)

$nextweek = date(m/d/Y,strtotime(+7 days));

-Rasmus

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



Re: [PHP] Date problems

2006-04-08 Thread Rasmus Lerdorf

Rasmus Lerdorf wrote:

Mace Eliason wrote:

Hi,

I am having troubles adding 7 days to the current date.  I have been 
reading through php.net date() and this is what I have come up with 
but it doesn't work

$today = date('m/d/Y');
$nextweek = date('m/d/Y',mktime(date(m), date(d)+7, date(Y)));

if I echo the above variables they are the same? Shouldn't the 
$nextweek be different?


You are thinking too much!  ;)

$nextweek = date(m/d/Y,strtotime(+7 days));


By the way, the reason your way isn't working is because you have your 
arguments wrong.  The first three arguments to mktime are hour, minute, 
second, and since you are only printing the date you lose the fact that 
you added 7 minutes.  If you try your script just before midnight you 
will notice the values are different.


-Rasmus

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



[PHP] date problems

2002-02-04 Thread toni baker

$date1 = 12/12/2001;
$date1 = date(D M j Y, strtotime($date1));
print $date1.br;

When I execute the code above I get the following
output:

Tue Dec 11 2001 instead Wed Dec !2 2001

Why does this happen and how can I get the Dec 12 
output?  Thanks






__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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





Re: [PHP] date problems

2002-02-04 Thread Jim Lucas [php]

sounds like it might have something to do with leap year.

Jim Lucas
- Original Message - 
From: toni baker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, February 04, 2002 12:03 PM
Subject: [PHP] date problems


 $date1 = 12/12/2001;
 $date1 = date(D M j Y, strtotime($date1));
 print $date1.br;
 
 When I execute the code above I get the following
 output:
 
 Tue Dec 11 2001 instead Wed Dec !2 2001
 
 Why does this happen and how can I get the Dec 12 
 output?  Thanks
 
 
 
 
 
 
 __
 Do You Yahoo!?
 Great stuff seeking new owners in Yahoo! Auctions! 
 http://auctions.yahoo.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 problems

2002-02-04 Thread Edward van Bilderbeek - Bean IT

i think it is the strtotime() function that gives the trouble... why don't
you try mktime() ?



 sounds like it might have something to do with leap year.

 Jim Lucas
 - Original Message -
 From: toni baker [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, February 04, 2002 12:03 PM
 Subject: [PHP] date problems


  $date1 = 12/12/2001;
  $date1 = date(D M j Y, strtotime($date1));
  print $date1.br;
 
  When I execute the code above I get the following
  output:
 
  Tue Dec 11 2001 instead Wed Dec !2 2001
 
  Why does this happen and how can I get the Dec 12
  output?  Thanks
 
 
 
 
 
 
  __
  Do You Yahoo!?
  Great stuff seeking new owners in Yahoo! Auctions!
  http://auctions.yahoo.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




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




[PHP] Date problems

2001-11-02 Thread Raymond C. Rodgers

Hi,
  I'm having a bit of a weird problem with the date() function. I am using 
PostgreSQL to store guestbook entries and updating and displaying them with 
Apache 1.3x and PHP4 on OpenBSD. The date information is being stored 
correctly in PostgreSQL, but I'm using the date() function to format the 
date to look nice like so:

 $date=date(l F j, Y n:i a T,strtotime($data-day_time));

to achieve:

 Friday November 2, 2001 11:27 am PST

The problem comes in that the time is a few hours off. In the above 
example, the time should have been 1:27 pm PST. In addition, the time for 
all the entries is off in what appears to be a sequence. The previous entry 
is off by three hours, the one before that is four hours off, and so on.

Any ideas about what might be happening? I know haven't given a lot of 
information, nor the actual URL, but I'm hoping it's just something simple 
that I'm doing wrong.

Thanks,
Raymond

--
Raymond C. Rodgers   [EMAIL PROTECTED]
Home Page:  http://bbnk.dhs.org


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]