Re: [PHP] Re: date problem

2005-06-29 Thread Mario netMines
Isn't DATEDIFF() a MySQL 4.x function? The server I'm using has 3.x and I 
can't upgrade...


- Original Message - 
From: Jasper Bryant-Greene [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Wednesday, June 29, 2005 7:49 AM
Subject: Re: [PHP] Re: date problem



Mario netMines wrote:

Hi Jasper and thanks for the quick reply.

something tells me it's not a straightforward SQL query that I have to
use here but a logic using PHP and SQL.


Please don't top-post.

It can be done in SQL quite easily, as can many things people use PHP
for. Go to the MySQL manual at http://dev.mysql.com/ and read up on
Date/Time functions, specifically the DATEDIFF() function. IIRC, it
returns the difference between two dates.

You can perform many types of arithmetic on the return value of the
function which should help to get the result you want. Try the MySQL
mailing lists if you can't figure it out, or if you're completely stuck
and are *convinced* it's a PHP problem (which I doubt, but I could be
wrong) then by all means come back!

Cheers

Jasper

--
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] Re: date problem

2005-06-28 Thread Jasper Bryant-Greene
Firstly, this shouldn't be in the PHP list, as you're asking for help
with SQL.

Mario netMines wrote:
 carrental_from (datetime field)
 carrental_to (datetime field)
 carrental_price (datetime field) [rates are per hour]

carrental_price shouldn't be a datetime field, as it isn't a datetime value.

 The values I have are like:
 -00-00 00:00:00,-00-00 07:00:00,10 (all year around 00:00-07:00)
 -00-00 07:00:00,-00-00 00:00:00,20 (all year around 07:00-00:00)
 2005-12-22 07:00:00,2006-01-02 00:00:00,15 (christmas period 00:00-07:00)
 2005-12-22 00:00:00,2006-01-02 07:00:00,25 (christmas period 07:00-00:00)
 
 The user selects dates ($from - $to) to rent a car and he gets the price
 accordingly.
 I can do a (($to-$from)/60/60) and get the total number of hours but
 depending on the date and time you get a different result. Can anyone
 help with the SQL?

Read up on the MySQL DATEDIFF() function, if you are using MySQL. Other
DBMSs should have an equiv. function.

Jasper

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



Re: [PHP] Re: date problem

2005-06-28 Thread Mario netMines

Hi Jasper and thanks for the quick reply.

something tells me it's not a straightforward SQL query that I have to use 
here but a logic using PHP and SQL.


Mario
- Original Message - 
From: Jasper Bryant-Greene [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Wednesday, June 29, 2005 4:28 AM
Subject: [PHP] Re: date problem



Firstly, this shouldn't be in the PHP list, as you're asking for help
with SQL.

Mario netMines wrote:

carrental_from (datetime field)
carrental_to (datetime field)
carrental_price (datetime field) [rates are per hour]


carrental_price shouldn't be a datetime field, as it isn't a datetime 
value.



The values I have are like:
-00-00 00:00:00,-00-00 07:00:00,10 (all year around 00:00-07:00)
-00-00 07:00:00,-00-00 00:00:00,20 (all year around 07:00-00:00)
2005-12-22 07:00:00,2006-01-02 00:00:00,15 (christmas period 00:00-07:00)
2005-12-22 00:00:00,2006-01-02 07:00:00,25 (christmas period 07:00-00:00)

The user selects dates ($from - $to) to rent a car and he gets the price
accordingly.
I can do a (($to-$from)/60/60) and get the total number of hours but
depending on the date and time you get a different result. Can anyone
help with the SQL?


Read up on the MySQL DATEDIFF() function, if you are using MySQL. Other
DBMSs should have an equiv. function.

Jasper

--
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] Re: date problem

2005-06-28 Thread Jasper Bryant-Greene
Mario netMines wrote:
 Hi Jasper and thanks for the quick reply.
 
 something tells me it's not a straightforward SQL query that I have to
 use here but a logic using PHP and SQL.

Please don't top-post.

It can be done in SQL quite easily, as can many things people use PHP
for. Go to the MySQL manual at http://dev.mysql.com/ and read up on
Date/Time functions, specifically the DATEDIFF() function. IIRC, it
returns the difference between two dates.

You can perform many types of arithmetic on the return value of the
function which should help to get the result you want. Try the MySQL
mailing lists if you can't figure it out, or if you're completely stuck
and are *convinced* it's a PHP problem (which I doubt, but I could be
wrong) then by all means come back!

Cheers

Jasper

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



[PHP] Re: date problem

2003-09-24 Thread John
For me, on Windows, it won't work because Windows won't do anything prior to
1970.

On linux, I get 17 as the result. If I change the year to 2000, then I get
08 on both.

John


Shaun [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 Why does the following code print '00', surely it should print '08', I'm
 baffled!

 date(H, mktime(8, 0, 0, 0, 0, 0));

 Thanks for your help

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



Re: [PHP] Re: date problem

2003-09-24 Thread Robert Cummings
From the documentation:

http://ca2.php.net/manual/en/function.mktime.php

Date with year, month and day equal to zero is considered
 illegal (otherwise it what be regarded as 30.11.1999, which
 would be strange behavior).

I think the point here to think about is that the date(), time(), and
mktime() functions all work with timestamps which happen to all function
with respect to the Unix Epoch (January 1 1970)

Cheers,
Rob.

On Wed, 2003-09-24 at 13:26, John wrote:
 For me, on Windows, it won't work because Windows won't do anything prior to
 1970.
 
 On linux, I get 17 as the result. If I change the year to 2000, then I get
 08 on both.
 
 John
 
 
 Shaun [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Hi,
 
  Why does the following code print '00', surely it should print '08', I'm
  baffled!
 
  date(H, mktime(8, 0, 0, 0, 0, 0));
 
  Thanks for your help
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Re: date problem

2003-03-19 Thread Philip Hallstrom
Try:

$ts = time();

$i = 0;
while( $i  2 ) {
$day = date(dS, $ts + $i * 86400);
print(td$day/td);
$i++;
}

On Wed, 19 Mar 2003, shaun wrote:

 hi,

 using date(dS); how can i can increase the days so that it shows

 19th 20th 21st

 I have tried

 while ($i  2){
   $day++;
   echo' td'.$day.'/td';
   $i++;
  }

 but i get:

 19th 19ti 19tj

 thanks for your 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



[PHP] Re: date problem

2003-02-27 Thread R'twick Niceorgaw
$date_array=explode(-,$newdate);
$day = $date_array[2];
$month = $date_array[1];
$year = $date_array[0];

Or,
$timestamp - strtotime($newdate);
$today = getdate($timestamp);
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];


Alexander Tsonev [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hello,
 I would ask you a question about date type
 if I have a variable from date type ($newdate) such as 2003-02-17
 how can I separate $newdate into 3 different variables? I want to create
 such variables:
 $day=17
 $month=2
 $year=2003
 I searched a lot, but I didn't find how to do this.
 I'll be very happy if someone helps!

 Thanks in advance, Alexander Tsonev







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



[PHP] Re: Date() Problem

2002-07-27 Thread Jome

 Hi, im making a tab/lyric portal, and for viewing tabs i want to display
the
 time the lyric/tab was submitted. So I retrive it from a MySQL database
(as
 a timestamp) and format it using the date function. The problem is, that
the
 date: 19-01-2038 04:14:07 is allways returned, even though in the `date`
 field the timestamp says (as an actual example) 20020723200919.

 Here is a shortened version of the script:

 ?php $submitdate = date(d-m-Y H:i:s, $values[4]); echo(Submitted on
 $submitdate); ?


Hi Tony,

the date() function in PHP does _only_ take UNIX timestamps as an argument
which means that you can not run such a timestamp as the above.

I recommend that you have a look at
http://www.mysql.com/doc/D/a/Date_and_time_functions.html which describes
the built-in functions for date-handling in MySQL. A function to look at
could be DATE_FORMAT().

Regards,

Jome



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




[PHP] Re: Date() Problem

2002-07-27 Thread Tony Harrison

Yeh, ive allready looked at that before, but where and when do i use
DATE_FORMAT() ? When im inserting the row or selecting it?

Jome [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Hi, im making a tab/lyric portal, and for viewing tabs i want to display
 the
  time the lyric/tab was submitted. So I retrive it from a MySQL database
 (as
  a timestamp) and format it using the date function. The problem is, that
 the
  date: 19-01-2038 04:14:07 is allways returned, even though in the `date`
  field the timestamp says (as an actual example) 20020723200919.
 
  Here is a shortened version of the script:
 
  ?php $submitdate = date(d-m-Y H:i:s, $values[4]); echo(Submitted on
  $submitdate); ?
 

 Hi Tony,

 the date() function in PHP does _only_ take UNIX timestamps as an argument
 which means that you can not run such a timestamp as the above.

 I recommend that you have a look at
 http://www.mysql.com/doc/D/a/Date_and_time_functions.html which describes
 the built-in functions for date-handling in MySQL. A function to look at
 could be DATE_FORMAT().

 Regards,

 Jome





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




[PHP] Re: Date() Problem

2002-07-27 Thread Jome

 Yeh, ive allready looked at that before, but where and when do i use
 DATE_FORMAT() ? When im inserting the row or selecting it?


Replace your existent query with this one and try:

SELECT
`artist_id`,`title`,`content`,`user_id`,DATE_FORMAT(date,'%d-%m-%Y
%H:%i:%s'),`type`,`views` FROM
`resources` WHERE `id` = $id

Regards,

Jome



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




[PHP] Re: Date() Problem

2002-07-27 Thread JJ Harrison

Alternativly you could store the dates as UNIX timestamps.

That is what I do. It is then eaiser to do certian things(ie show stuff
released in the last month)


--
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com

Tony Harrison [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Yeh, ive allready looked at that before, but where and when do i use
 DATE_FORMAT() ? When im inserting the row or selecting it?

 Jome [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   Hi, im making a tab/lyric portal, and for viewing tabs i want to
display
  the
   time the lyric/tab was submitted. So I retrive it from a MySQL
database
  (as
   a timestamp) and format it using the date function. The problem is,
that
  the
   date: 19-01-2038 04:14:07 is allways returned, even though in the
`date`
   field the timestamp says (as an actual example) 20020723200919.
  
   Here is a shortened version of the script:
  
   ?php $submitdate = date(d-m-Y H:i:s, $values[4]); echo(Submitted
on
   $submitdate); ?
  
 
  Hi Tony,
 
  the date() function in PHP does _only_ take UNIX timestamps as an
argument
  which means that you can not run such a timestamp as the above.
 
  I recommend that you have a look at
  http://www.mysql.com/doc/D/a/Date_and_time_functions.html which
describes
  the built-in functions for date-handling in MySQL. A function to look at
  could be DATE_FORMAT().
 
  Regards,
 
  Jome
 
 





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




[PHP] Re: Date() Problem

2002-07-27 Thread Tony Harrison

I tried using UNIX stamps but it dont work, and why the hell does it default
to that date anyway? I thought it was supposed to default to the current
time?

Jj Harrison [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Alternativly you could store the dates as UNIX timestamps.

 That is what I do. It is then eaiser to do certian things(ie show stuff
 released in the last month)


 --
 JJ Harrison
 [EMAIL PROTECTED]
 www.tececo.com

 Tony Harrison [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Yeh, ive allready looked at that before, but where and when do i use
  DATE_FORMAT() ? When im inserting the row or selecting it?
 
  Jome [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
Hi, im making a tab/lyric portal, and for viewing tabs i want to
 display
   the
time the lyric/tab was submitted. So I retrive it from a MySQL
 database
   (as
a timestamp) and format it using the date function. The problem is,
 that
   the
date: 19-01-2038 04:14:07 is allways returned, even though in the
 `date`
field the timestamp says (as an actual example) 20020723200919.
   
Here is a shortened version of the script:
   
?php $submitdate = date(d-m-Y H:i:s, $values[4]); echo(Submitted
 on
$submitdate); ?
   
  
   Hi Tony,
  
   the date() function in PHP does _only_ take UNIX timestamps as an
 argument
   which means that you can not run such a timestamp as the above.
  
   I recommend that you have a look at
   http://www.mysql.com/doc/D/a/Date_and_time_functions.html which
 describes
   the built-in functions for date-handling in MySQL. A function to look
at
   could be DATE_FORMAT().
  
   Regards,
  
   Jome
  
  
 
 





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




Re: [PHP] Re: Date() Problem

2002-07-27 Thread Justin French

I store all dates in unix timestamp format.  It's the easiest one to work
with, and it's easy to do things like date + three days, because it's just
a case of adding the right number of seconds to the current stamp.

You don't have to split anything, or get substr()'s of anything... and since
date() accepts unix timestamps AND is the easiest way to get date formats
(for me), I reckon it's the best way to go.


Justin


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




RE: [PHP] Re: Date() Problem

2002-07-27 Thread John Holmes

 I store all dates in unix timestamp format.  It's the easiest one to
work
 with, and it's easy to do things like date + three days, because
it's
 just
 a case of adding the right number of seconds to the current stamp.
 
 You don't have to split anything, or get substr()'s of anything... and
 since
 date() accepts unix timestamps AND is the easiest way to get date
formats
 (for me), I reckon it's the best way to go.

Well, I've got to butt in on this one and put in a big DISAGREE. Use
whatever is easiest for you, but MySQL provides a very rich assortment
of date and time manipulation functions that are a lot better than PHPs
(without any added classes). 

For example, to get everything from your database that was inserted
three days ago, you'd use:

SELECT * FROM your_table WHERE your_date_column = CURDATE() - INTERVAL 3
DAY;

Now, much of this is MySQL specific, though. I only use MySQL right now,
so it's not an issue, but it can be for some of you. 

Bottom line is use whatever is easiest for you, but realize that there
are a ton of Date and Time functions built into MySQL. Anything you can
do with a PHP function you can do with a MySQL function. You are also
not completely lost if you're storing things as Unixtimstamps. You can
convert from and to unixtimestamps and still make use of all of the
MySQL functions...

---John Holmes...


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




[PHP] Re: date problem

2002-04-28 Thread Yuri Petro

You can include date formatting function in your SQL statement:
DATE_FORMAT(date,format)
http://www.mysql.com/doc/D/a/Date_and_time_functions.html

--
Kind regards,
Yuri.

 www.AceHoster.com  Quality web hosting


Nick Wilson [EMAIL PROTECTED] ???/ ?  ?:
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Hi all
 I have a field in MySQL db like this: date TIMESTAMP,
 and it looks pretty regular like this: 20020428011911

 when I come to use php date(D M Y, $myTimeStamp) though I get

 TUE JAN 2038!

 I see something in the manual re this date but I'm afraid I still can't
 work it out so some advice/help would be greatly appreciated :-)

 - --
 Nick Wilson //  www.explodingnet.com



 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.0.6 (GNU/Linux)

 iD4DBQE8y++SHpvrrTa6L5oRAh3xAJ9lfFdB1VW3KUHCWxnnksN+Uw950QCYpfg6
 OCdApC0Nh/8hi8MYQY3OTQ==
 =FnlM
 -END PGP SIGNATURE-



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




[PHP] Re: date problem

2002-02-18 Thread Julio Nobrega Trabalhando

  Mysql?

INSERT INTO table VALUES (NOW());

--

Julio Nobrega.

Um dia eu chego lá:
http://sourceforge.net/projects/toca

Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884


Eoghan [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 hello

 i am running into some trouble with a very basic problem.
 i want to insert the current date/time into my db. i have
 the field set up as a datetime field. when i submit info,
 i just get a blank date, i mean it all zeros, like
 -00-00 00.00:00:00. how do i insert the current datetime
 into my db? i tried using a hidden field with a foramtted
 gmt date value, but its not working... any help

 thanks - eoghan



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




[PHP] Re: Date Problem

2001-11-28 Thread lallous

you can use the MySql's function:

DATE_ADD(datefield, INTERVAL 3 MONTH)

Mindhunter [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi,

 I am reading a date from an input in format 'DD-MM-' ex. 10-11-2001.
 Now I want to add 3 months to the date.  I have tested mktime and strftime
 etc and no matter what I do I get the year as 1970.  (Systemdate works
 fine).  How would I go about adding 3 months to a date in that format?

 Thanks
 MH





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




[PHP] Re: Date Problem

2001-11-21 Thread David Tod Sigafoos

On Wed, 21 Nov 2001 09:31:33 +0200, [EMAIL PROTECTED]
(Mindhunter) wrote:

I am reading a date from an input in format 'DD-MM-' ex. 10-11-2001.
Now I want to add 3 months to the date.  I have tested mktime and strftime
etc and no matter what I do I get the year as 1970.  (Systemdate works
fine).  How would I go about adding 3 months to a date in that format?

Though not the most elegant solution by far ..

You could explode the data  the increment the second element of the
array.  If gt 12 subtract 12 and increment the year ..

Sorry .. the date functions still get me.

DSig

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




[PHP] Re: Date Problem

2001-11-21 Thread George Whiffen

Mindhunter wrote:
 
 Hi,
 
 I am reading a date from an input in format 'DD-MM-' ex. 10-11-2001.
 Now I want to add 3 months to the date.  I have tested mktime and strftime
 etc and no matter what I do I get the year as 1970.  (Systemdate works
 fine).  How would I go about adding 3 months to a date in that format?
 
 Thanks
 MH
The following works for me:

$mydate = '10-11-2001';

list($myday,$mymonth,$myyear) = explode('-',$mydate);

$mymktime = mktime(0,0,0,3 + $mymonth,$myday,$myyear);

$newdate = date('d-m-Y',$mymktime);

newdate is then 10-02-2002

You might check : 
1. You always use a 4 digit year
2. mktime order of arguments i.e. hours,minutes,seconds,months,days,years 
3. Output date format on date() function
4. There are problems with dates pre 1970 AND pre 1901, (pre 1970 is pre unixtime, pre 
1901 is pre
phptime).  I had problems with pre 1901 dates which the calendar module solved ( see 
jdtojulian,
juliantojd)

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




[PHP] Re: date problem

2001-11-01 Thread Chris Lee

date() shoudl give you the time in your timezone, gmdate() should give you
the time in the GMT timezone. I would check your server and make sure the
timezone is correctly set.

--

  Chris Lee
  [EMAIL PROTECTED]



Steve Tsai [EMAIL PROTECTED] wrote in message news:none...
 For reference:
 OS: OpenBSD 2.9
 Web Server: Apache1.3.19
 PHP Version: 4.0.6

 My problem is that date() and all the other time functions return GMT
instead
 of localtime.  system(date) returns the correct localtime.  Those
functions
 used to return localtime since GMT.  The problem seems to have started
after
 daylight savings time changed.  I hope someone has an idea of what's wrong
 and how to fix it.  As for now, I'm adding time() - 3600 * 8 to all my
 scripts right now.

 Steve



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