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

2012-11-11 Thread Jim Giner

On 11/11/2012 1:30 PM, 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

Besides the minor fact that the code has syntax errors, the problem with 
it is your if is backwrads.  The facts are: today is less than end date, 
so your if should show The show has ended since you are asking if 
today IS GREATER than the end date.


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



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

2012-11-11 Thread Jim Giner


BTW - this is the code I used to test out your process:

?
$dt_format = D, M jS, Y g:i:s a;
$todaydate = date($dt_format);
$showenddate = strtotime(11/18/12 16:00:00);
if ($todaydate  $showenddate)
echo The date of the show has not yet arrived;
else
echo The show has ended;

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



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

2012-11-11 Thread Maciek Sokolewicz

On 11-11-2012 22:47, Jim Giner wrote:

Besides the minor fact that the code has syntax errors, the problem with
it is your if is backwrads.  The facts are: today is less than end date,
so your if should show The show has ended since you are asking if
today IS GREATER than the end date.

BTW - this is the code I used to test out your process:

?
$dt_format = D, M jS, Y g:i:s a;
$todaydate = date($dt_format);
$showenddate = strtotime(11/18/12 16:00:00);
if ($todaydate  $showenddate)
echo The date of the show has not yet arrived;
else
echo The show has ended;



Not only is the logic wrong, but date returns a string, while strtotime 
returns an int. Comparing those two to eachother is just... wrong.

Comparing 2 integers and saying one is bigger than the other: ok
Comparing a string and an integer, saying one is bigger than the other: 
recipe for failure.


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



[PHP] Re: Date validation

2011-05-23 Thread Pete Ford

On 20/05/11 16:29, Geoff Lane wrote:

On Friday, May 20, 2011, Peter Lind wrote:


Try:



$date = new DateTime($date_string_to_validate);
echo $date-format('Y-m-d');


Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date-format('Y-m-d');

which results in 1999-03-02 even though 30 Feb is an invalid date.



If you could programmatically determine the format of the input, you could parse 
the date using DateTime and then rewrite it using the same format as the input, 
and compare those.
Now that starts to work if you can *control* the format of the input, or at 
least limit it to some familiar options.


So maybe:

$userInput = '30 Feb 1999';
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest-format('Y-m-d') ||
$userInput===$dateTest-format('d M Y'))
{
echo 'Date is valid';
}
else
{
echo 'Not valid';
}

It starts to get logn-winded after a while, and doesn't rule out ambiguous 
cases...
Or split the date input into pieces in the form (if possible) and then you can 
validate the date how you like


$userInput = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest-format('Y-m-d'))
{
echo 'Date is valid';
}
else
{
echo 'Not valid';
}


Finally, for some applications I have made an AJAX (javascript + PHP) 
implementation which provides feedback to the user as they type in the date 
field: every time a character is typed in the box, the backend is asked to parse 
it and then format it in an unambiguous way and send it back to the client. That 
way the user can *see* if what they are typing is valid...
Of course, you *still* have to validate it when it's posted (and the network 
overhead might be too much).




--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

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



[PHP] Re: Date validation

2011-05-23 Thread tedd

At 9:47 AM +0100 5/23/11, Pete Ford wrote:
Finally, for some applications I have made an AJAX (javascript + 
PHP) implementation which provides feedback to the user as they type 
in the date field: every time a character is typed in the box, the 
backend is asked to parse it and then format it in an unambiguous 
way and send it back to the client. That way the user can *see* if 
what they are typing is valid...
Of course, you *still* have to validate it when it's posted (and the 
network overhead might be too much).


That would be interesting to see.

With a little work, I envision a way to alleviate the Europe/US date 
format difference. (i.e., day/month/year : Europe vs month/day/year : 
US).


As the user typed in the date, the day/month problem could be shown 
via string-month (i.e., Jan... ).


How does yours work?

Cheers,

tedd

--
---
http://sperling.com/

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



Re: [PHP] Re: Date validation

2011-05-23 Thread Pete Ford

On 23/05/11 13:12, tedd wrote:

At 9:47 AM +0100 5/23/11, Pete Ford wrote:

Finally, for some applications I have made an AJAX (javascript + PHP)
implementation which provides feedback to the user as they type in the
date field: every time a character is typed in the box, the backend is
asked to parse it and then format it in an unambiguous way and send it
back to the client. That way the user can *see* if what they are
typing is valid...
Of course, you *still* have to validate it when it's posted (and the
network overhead might be too much).


That would be interesting to see.

With a little work, I envision a way to alleviate the Europe/US date
format difference. (i.e., day/month/year : Europe vs month/day/year : US).

As the user typed in the date, the day/month problem could be shown via
string-month (i.e., Jan... ).

How does yours work?

Cheers,

tedd


Ah, now you're asking.
I'll have to try and extract the code into a sanitised form for public 
consumption: give me a little time...
But yes, the string fed back to the user gives the month as a string, to avoid 
confusion with numeric months.


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

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



Re: [PHP] Re: Date validation

2011-05-23 Thread Tamara Temple

Isn't this typically why date selectors are used on the front end?

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



Re: [PHP] Re: Date validation

2011-05-23 Thread Andrew Ballard
On Mon, May 23, 2011 at 9:55 AM, Tamara Temple tamouse.li...@gmail.com wrote:
 Isn't this typically why date selectors are used on the front end?


Not really. Date selectors are intended to make data entry easier on
the front end while allowing only valid date selections, but you can't
really rely on them.

* Most date selectors rely on Javascript, which may not be available
on the client.

* From a usability perspective, using a date selector is slower than
typing the date into a text field. Accessibility is also a concern.

* Above all, your code should still validate the correctness of input
on the server regardless of anything you are doing to make things
easier in the client. There are ways around using date selectors.

Andrew

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



[PHP] Re: Date validation

2011-05-21 Thread Geoff Lane
I'm posting here for completeness as I've now rolled my own date
validator (code follows my sig). It allows almost all valid 'English'
formats except ordinal day values (1st, 3rd, etc.) Because I'm in UK
and writing for a UK audience, I've parsed ambiguous dates as d/m/y.
Those writing for places where m/d/y is the convention will probably
want to alter the tests in the second if ... elseif construct. It's a
bit long-winded, but by all means use or modify if it's any use to
you.

Best regards,

Geoff

---8--

function is_date ($str){
$dateOK = TRUE;
if (stristr($str, /)){
$aryDate = explode (/, $str);
} elseif (stristr($str, -)){
$aryDate = explode (-, $str);
} elseif (stristr($str,  )){
$aryDate = explode ( , $str);
} else {
$dateOK = FALSE;
}
if (count($aryDate) != 3){
// we don't have the correct number of date parts
$dateOK = FALSE;
}
if ($dateOK) {
// trim any leading or trailing whitespace
for ($i = 0; $i  count($aryDate); $i++){
$aryDate[$i] = trim($aryDate[$i]);
}
// determine which value is month and which is day
if (!is_numeric($aryDate[0])){
$month = $aryDate[0];
$day = $aryDate[1];
} elseif (!is_numeric($aryDate[1])){
$day = $aryDate[0];
$month = $aryDate[1];
} elseif ($aryDate[1] = 12){
$day = $aryDate[0];
$month = $aryDate[1];
} else {
$month = $aryDate[0];
$day = $aryDate[1];
}
$year = $aryDate[2];
// Expand 2-digit years to 4 digits. Cut-off is current year + 10.
if (strlen($year) != 4){
$now = date('y') + 10;
$year = $year - $now  0 ? '20' . $year : '19' . $year;
// check for correct year length
if (strlen($year) != 4){
// we didn't start with two digits
$dateOK = FALSE;
}
}
// Convert month names to month numbers
if (!is_numeric($month)){
$aryMonth = array('nowt', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 
'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
$month = strtolower(substr($month, 0, 3));
foreach ($aryMonth AS $key = $value){
if ($value == $month){
$month = $key;
}
}
}
$dateOK = $dateOK  checkdate($month, $day, $year);
}
return ($dateOK);
}


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



[PHP] Re: Date validation

2011-05-20 Thread Jo�o C�ndido de Souza Neto
What about using this:

$date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

-- 
João Cândido de Souza Neto

Geoff Lane ge...@gjctech.co.uk escreveu na mensagem 
news:11565581.20110520132...@gjctech.co.uk...
 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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
 On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using this:

 $date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

Hi João, and thanks for your help.

FWIW, I thought about that but it didn't work for me. On further
investigation, I'm now completely confused and suspect I've got a duff
PHP installation. Thankfully, it's a virtual machine so it should be
reasonable easy to 'vapourise' and start over (perhaps with CentOS
rather than Ubuntu as the OS).

Anyway, the following code produces the following result when the
variable $str = '7 feb 2010':

[code]
  echo pDate is $str/p\n;
  $date = DateTime::createFromFormat('d M Y', $str);
  echo pre;
  print_r($date);
  echo /pre\n;
  echo date('d M Y') . br / . date('d M Y', $date);
[/code]

[result]
  pDate is 7 feb 2010/p
  preDateTime Object
  (
  [date] = 2010-02-07 15:11:34
  [timezone_type] = 3
  [timezone] = Europe/London
  )
  /pre
  20 May 2011br /
[/result]

This is pretty much as expected except that the second call to date()
- i.e. date('d M Y', $date) - outputs nothing.

Also, AFAICT createFromFormat fails if the date is not formatted
according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
fails ... (at least, it does on my system :( )

-- 
Geoff


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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
On 20 May 2011 16:22, Geoff Lane ge...@gjctech.co.uk wrote:
  On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using this:

 $date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

 Hi João, and thanks for your help.

 FWIW, I thought about that but it didn't work for me. On further
 investigation, I'm now completely confused and suspect I've got a duff
 PHP installation. Thankfully, it's a virtual machine so it should be
 reasonable easy to 'vapourise' and start over (perhaps with CentOS
 rather than Ubuntu as the OS).

 Anyway, the following code produces the following result when the
 variable $str = '7 feb 2010':

 [code]
  echo pDate is $str/p\n;
  $date = DateTime::createFromFormat('d M Y', $str);
  echo pre;
  print_r($date);
  echo /pre\n;
  echo date('d M Y') . br / . date('d M Y', $date);
 [/code]

 [result]
  pDate is 7 feb 2010/p
  preDateTime Object
  (
      [date] = 2010-02-07 15:11:34
      [timezone_type] = 3
      [timezone] = Europe/London
  )
  /pre
  20 May 2011br /
 [/result]

 This is pretty much as expected except that the second call to date()
 - i.e. date('d M Y', $date) - outputs nothing.

date() takes an int as second parameter - a timestamp. Not an object.
And from a quick test it doesn't look like DateTime has a __toString
method.

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


I'm sorry for asking but what did you expect?? You're specifically
calling a method that parses a string according to a given format. If
it parsed the string according to any other format, that would be a
huge WTF.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Date validation

2011-05-20 Thread Jo�o C�ndido de Souza Neto
If you look carefully, you´ll notice that I´m using the DateTime object 
(default from PHP 5.2.0 or higher) not the function date.

-- 
João Cândido de Souza Neto

Peter Lind peter.e.l...@gmail.com escreveu na mensagem 
news:banlktinjonyvfnqjqtfqtdmu_r2-cfp...@mail.gmail.com...
On 20 May 2011 16:22, Geoff Lane ge...@gjctech.co.uk wrote:
 On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using this:

 $date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

 Hi João, and thanks for your help.

 FWIW, I thought about that but it didn't work for me. On further
 investigation, I'm now completely confused and suspect I've got a duff
 PHP installation. Thankfully, it's a virtual machine so it should be
 reasonable easy to 'vapourise' and start over (perhaps with CentOS
 rather than Ubuntu as the OS).

 Anyway, the following code produces the following result when the
 variable $str = '7 feb 2010':

 [code]
 echo pDate is $str/p\n;
 $date = DateTime::createFromFormat('d M Y', $str);
 echo pre;
 print_r($date);
 echo /pre\n;
 echo date('d M Y') . br / . date('d M Y', $date);
 [/code]

 [result]
 pDate is 7 feb 2010/p
 preDateTime Object
 (
 [date] = 2010-02-07 15:11:34
 [timezone_type] = 3
 [timezone] = Europe/London
 )
 /pre
 20 May 2011br /
 [/result]

 This is pretty much as expected except that the second call to date()
 - i.e. date('d M Y', $date) - outputs nothing.

date() takes an int as second parameter - a timestamp. Not an object.
And from a quick test it doesn't look like DateTime has a __toString
method.

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
 $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


I'm sorry for asking but what did you expect?? You're specifically
calling a method that parses a string according to a given format. If
it parsed the string according to any other format, that would be a
huge WTF.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype 



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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
2011/5/20 João Cândido de Souza Neto j...@consultorweb.cnt.br:
 If you look carefully, you´ll notice that I´m using the DateTime object
 (default from PHP 5.2.0 or higher) not the function date.

If you look carefully, you'll notice that I replied to Geoff.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
 On Friday, May 20, 2011, Peter Lind wrote:

 This is pretty much as expected except that the second call to
 date() - i.e. date('d M Y', $date) - outputs nothing.

 date() takes an int as second parameter - a timestamp. Not an object.
 And from a quick test it doesn't look like DateTime has a __toString
 method.

Thanks - my misunderstanding. I'll have to look into that further.

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


 I'm sorry for asking but what did you expect?? You're specifically
 calling a method that parses a string according to a given format. If
 it parsed the string according to any other format, that would be a
 huge WTF.

Don't feel sorry to have asked, because it's exactly what I expected.
João suggested using createFromFormat. Since I need to validate dates
input in any valid form, I felt it wouldn't work and my comment was to
João to that effect. That said, I've seen some weird and unexpected
results from my development server recently (e.g. my post of 16 May re
weird cookie behaviour) which was why I added the proviso (at least,
it does on my system) just in case that method wasn't meant to behave
as I inferred.

With all that said, I still have no 'out of the box' method to
validate a user-input date string and I haven't been able to find the
code I used with PHP 3.something before my sojourn into the depths of
ASP to know how I used to do this!

-- 
Geoff


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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
On 20 May 2011 16:47, Geoff Lane ge...@gjctech.co.uk wrote:

*snip*

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


 I'm sorry for asking but what did you expect?? You're specifically
 calling a method that parses a string according to a given format. If
 it parsed the string according to any other format, that would be a
 huge WTF.

 Don't feel sorry to have asked, because it's exactly what I expected.
 João suggested using createFromFormat. Since I need to validate dates
 input in any valid form, I felt it wouldn't work and my comment was to
 João to that effect. That said, I've seen some weird and unexpected
 results from my development server recently (e.g. my post of 16 May re
 weird cookie behaviour) which was why I added the proviso (at least,
 it does on my system) just in case that method wasn't meant to behave
 as I inferred.

 With all that said, I still have no 'out of the box' method to
 validate a user-input date string and I haven't been able to find the
 code I used with PHP 3.something before my sojourn into the depths of
 ASP to know how I used to do this!


My bad, I jumped into the middle of a thread - sorry.

Try:

$date = new DateTime($date_string_to_validate);
echo $date-format('Y-m-d');

Regards
Peter

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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
On Friday, May 20, 2011, Peter Lind wrote:

 Try:

 $date = new DateTime($date_string_to_validate);
 echo $date-format('Y-m-d');

Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date-format('Y-m-d');

which results in 1999-03-02 even though 30 Feb is an invalid date.

-- 
Geoff


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



[PHP] Re: Date validation

2011-05-20 Thread Geoff Lane
On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using regular expression to validate so using DateTime
 object to  parse it if it?s a valid date?

Again, thanks.

For info, I only need to know that it's a valid representation of a
date on this occasion as I intend to use the MySQL CAST function to do
the actual conversion within the INSERT or UPDATE SQL statement that
commits the value to the underlying database.

I strongly suspect that you're correct in that I should be able to use
a regexp to do the validation. This could well be the catalyst that
gets my sleeves rolled up, a large pot of strong, black coffee on the
hob, and me finally trying that little bit harder to get my head
around regular expressions!

I was hoping that PHP would have an equivalent to VBScript's IsDate()
function but it looks like I'll have to roll my own!

Thanks again,

-- 
Geoff


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



[PHP] Re: Date +30 comparison

2009-09-01 Thread Shawn McKenzie
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.

Look at the date/time functions, they are very feature rich:

$today = time();
$nexteval = strtotime('+30 days', $today);

if ($today  $nexteval) {
echo 'Message';
}

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: Date math

2008-03-24 Thread Bill Guion

At 12:17 AM -0400 3/24/08, Ron Piggott wrote:


I have this math equation this list helped me generate a few weeks ago.
The purpose is to calculate how many days have passed between 2 dates. 

Right now my output ($difference) is 93.958333 days. 


I am finding this a little weird.  Does anyone see anything wrong with
the way this is calculated:

$date1 = strtotime($date1); (March 21st 2008)
$date2 = strtotime($date2); (December 18th 2007)

echo $date1 = 1206072000
echo $date2 = 1197954000

#86400 is 60 seconds x 60 minutes x 24 hours (in other words 1 days
worth of seconds)

$factor = 86400;

$difference = (($date1 - $date2) / $factor);


94 - 93.958333 = .04167

.04167 * 86400 = 3600 = 1 hour. Didn't you pass throught 
daylight savings time prior to 21 March?


 -= Bill =-
--

You can't tell which way the train went by looking at the track.
  



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



[PHP] Re: date formatting

2007-08-30 Thread Haydar TUNA
Hello,
 You can DATE_FORMAT MySQL Command in your SQL Query. For example:
select DATE_FORMAT(yourdatetimefield,'%Y-%m-%d') from yourtable

-- 
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net

Mike Ryan [EMAIL PROTECTED], haber iletisinde þunlarý 
yazdý:[EMAIL PROTECTED]
I would like to have my users input the date formate as mm-dd- mysql
 wants the data to come down as -mm-dd.

 The question I have is how do I convert from the mm-dd- to -mm-dd 
 so
 that I can write it out to the database? 

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



[PHP] Re: Date Calculation Help

2007-06-30 Thread Oliver Jato
revDAVE wrote:

 I have segmented a year into four quarters (3 months each)
 
 nowdate = the month of the chosen date (ex: 5-30-07 = month 5)
 
 Q: What is the best way to calculate which quarter  (1-2-3 or 4) the
 chosen date falls on?
 
 Result - Ex: 5-30-07 = month 5 and should fall in quarter 2

You could do it like this: floor(($month-1)/3)+1;

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



[PHP] Re: date format from a database date field

2007-05-23 Thread Johan Holst Nielsen

Mike Ryan wrote:

Sorry I am a bit of a newbie with php and hope this has not been aswered a
million times, but here it goes

I have a date base with a couple of date fields when I pull up and display
the fields it show 2007-05-21. the question I have is how to convert the
field to 05-21-2007?

Currently the command I have is

print $row['open'];


Well the easiest thing is to let MySQL do the work

use following SELECT

SELECT DATE_FORMAT(your_date_field,'%m-%d-%Y') as date_field FROM yourtable

That should do the work...

--
Johan Holst Nielsen
Freelance PHP Developer - http://phpgeek.dk

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



Re: [PHP] Re: date() and timezone

2006-12-15 Thread Fernando M. M.


Hello,


 But like i said i have lots of scripts inside
this
 folder, is there a way to set something on .htaccess to change
the timezone?

 
 why? ;-)

Because i can't set
the timezone for every single script. Inside this folder and subfolders i guess 
there
are about 10,000 scripts.

 What you were pointed to before + 
  http://us3.php.net/manual/de/ini.php#ini.list
 
 ah, now
you've gone and made it easy for him :-)
 

Actually i don't have
access to php.ini file. Are there any other ways to do this?

-- 

Blog: http://blog.forumdebian.com.br/fernando
Contato:
http://www.forumdebian.com.br/fernando/contato.php


Re: [PHP] Re: date() and timezone

2006-12-15 Thread Jochem Maas
Fernando M. M. wrote:
 
 Hello,
 
 
 But like i said i have lots of scripts inside
 this
 folder, is there a way to set something on .htaccess to change
 the timezone?
 why? ;-)
 
 Because i can't set
 the timezone for every single script. Inside this folder and subfolders i 
 guess there
 are about 10,000 scripts.

that will teach not to use global include files to init your apps.

even if you we stuck with editing 10,000 scripts (btw it sounds very fishy
to 10,000 scripts with date() calls in them - can anyone say 'code reuse'?)
exactly how hard would it be to write something that would go through all
those php files and add a single line ( ini_set('date.timezone', 
'Europe/Amsterdam'); )
to the top of the script (i.e. just after the first '?php' | '?') ?

 
 What you were pointed to before + 
  http://us3.php.net/manual/de/ini.php#ini.list
 ah, now
 you've gone and made it easy for him :-)
 
 Actually i don't have
 access to php.ini file. 

if you RTFM (and I mean actually READ) then you would know that you
can set the relevant date related ini settings in a .htaccess file

here is the relevant link again:

http://php.net/manual/en/ref.datetime.php#ini.date.timezone


 Are there any other ways to do this?
 


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



Re: [PHP] Re: date() and timezone

2006-12-15 Thread Fernando M. M.


 
 that will teach not to use global include files to init your apps.
 
 even if you we stuck with editing 10,000 scripts (btw it sounds very
fishy
 to 10,000 scripts with date() calls in them - can anyone say 'code
reuse'?)
 exactly how hard would it be to write something that would go through
all
 those php files and add a single line ( ini_set('date.timezone',
'Europe/Amsterdam');
 )
 to the top of the script (i.e. just
after the first '?php' | '?') ?

Those scripts are uploaded by a lot
of people. Unfortunately i can't make all of them change this conf. But now i 
know that
i can change this on .htaccess


 
 if you RTFM (and I mean
actually READ) then you would know that you
 can set the relevant date related
ini settings in a .htaccess file
 
 here is the relevant link
again:
 

http://php.net/manual/en/ref.datetime.php#ini.date.timezone
 
 

Sorry, i have read it but i was reading the portuguese version and it seens like
it is not completely translated. Just changed to the english version and NOW i 
can read
it :)

Thanks,

Fernando.
-- 

Blog:
http://blog.forumdebian.com.br/fernando
Contato:
http://www.forumdebian.com.br/fernando/contato.php


Re: [PHP] Re: date() and timezone

2006-12-15 Thread Jochem Maas
Fernando M. M. wrote:
 
 that will teach not to use global include files to init your apps.

 even if you we stuck with editing 10,000 scripts (btw it sounds very
 fishy
 to 10,000 scripts with date() calls in them - can anyone say 'code
 reuse'?)
 exactly how hard would it be to write something that would go through
 all
 those php files and add a single line ( ini_set('date.timezone',
 'Europe/Amsterdam');
 )
 to the top of the script (i.e. just
 after the first '?php' | '?') ?
 
 Those scripts are uploaded by a lot
 of people. Unfortunately i can't make all of them change this conf. 

I was suggesting you write a script to programmatically hack all the files in 
question,
but its a moot point you've seen that there is a sane way of tackling the issue.

 But now i know that
 i can change this on .htaccess
 
 
 if you RTFM (and I mean
 actually READ) then you would know that you
 can set the relevant date related
 ini settings in a .htaccess file
 here is the relevant link
 again:

   http://php.net/manual/en/ref.datetime.php#ini.date.timezone

 
 Sorry, i have read it but i was reading the portuguese version and it seens 
 like
 it is not completely translated. Just changed to the english version and NOW 
 i can read
 it :)

ah that explains alot - my advice is always use the english version of the 
manual if you can,
no disrespect to the many hard-working translators out there but there is 
almost no chance any
translation team can keep up the number and frequency of updates to the docs.

for the same reason I recommend never using an offline version of the manual 
unless you
have no other choice.

 
 Thanks,
 
 Fernando.

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



[PHP] Re: date() and timezone

2006-12-14 Thread Jonesy
On Thu, 14 Dec 2006 16:56:55 -0200 (BRST), Fernando M. M. wrote:
 --=_20061214165655_35409
 Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: 8bit

 I´m using php5 here.

 But like i said i have lots of scripts inside this
 folder, is there a way to set something on .htaccess to change the timezone?

Please don't top post.

RTFM you were pointed to: Instead of using this function to set the 
default timezone in your script, you can also use the INI setting 
date.timezone to set the default timezone.

What you were pointed to before + 
 http://us3.php.net/manual/de/ini.php#ini.list

Jonesy
-- 
  Marvin L Jones| jonz  | W3DHJ  | linux
   38.24N  104.55W  |  @ config.com | Jonesy |  OS/2
*** Killfiling google posts: http//jonz.net/ng.htm

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



Re: [PHP] Re: date() and timezone

2006-12-14 Thread Jochem Maas
Jonesy wrote:
 On Thu, 14 Dec 2006 16:56:55 -0200 (BRST), Fernando M. M. wrote:
 --=_20061214165655_35409
 Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: 8bit

 I´m using php5 here.

 But like i said i have lots of scripts inside this
 folder, is there a way to set something on .htaccess to change the timezone?
 

why? ;-)

 Please don't top post.
 
 RTFM you were pointed to: Instead of using this function to set the 
 default timezone in your script, you can also use the INI setting 
 date.timezone to set the default timezone.
 
 What you were pointed to before + 
  http://us3.php.net/manual/de/ini.php#ini.list

ah, now you've gone and made it easy for him :-)

 
 Jonesy

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



[PHP] Re: date(n/Y) strtotime

2006-08-02 Thread Adam Zey

Mark Steudel wrote:

I've always been really amazed at how well strtotime works, but recently
ran into an issue where it couldn't figure out the date if it was a cc
exp date in long format, e.g. 1/2009. I was curious if anyone else has
run into this and how did they get around it, here was my solution:

function expDate2str( $date )
{
if( !($sDate = strtotime( $date ) ) )
{
// exploded date
$eDate = explode( '/', $date );

// string date we hard code the day to 1
$sDate = strtotime( date( Y-m-d, mktime( 0, 0, 0,
$eDate[0], 1, $eDate[1] ) ) );


}

return $sDate;
}

Thanks, Mark

--
Mark Steudel
Web Applications Developer
555 Dayton St 
Suite A

Edmonds, WA 98020
p: 425.741.7014
e: [EMAIL PROTECTED]
w: http://www.netriver.net


I usually just munge the string and toss it into strtotime.

For credit card expiration dates, I'd just do this (Not going to the 
lengths of your solution, just the conversion part):


$timestamp = strtotime(str_replace(/, /01/, $date));

That will turn 9/2006 into 9/01/2006 which is a GNU compatible date that 
strtotime should be able to understand. It assumes that the input date 
is in a certain format, but it's simpler than your solution of 
exploding, then using date and mktime.


One caveat is that I'm uncertain if you need to have a trailing zero for 
the month. The GNU page is somewhat unclear as it has conflicting info. 
You may simply want to do these two lines instead:


if ( strlen($date) == 6 ) $date = 0 . $date;
$timestamp = strtotime(str_replace(/, /01/, $date));

Which will add the preceding zero to a date in the 9/2006 format if 
required. Those two lines would get you 09/01/2006


Here's an even simpler example, which uses a ternary operator to do it 
in one line:


$timestamp = strtotime(str_replace(/, /01/, strlen($date) == 6 ? 0 
. $date : $date));


That will also result in 09/01/2006. Note that where we're passing 
str_replace the source string to work on, we have a ternary (think of it 
as an inline if statement) that checks the length, and either returns 
$date, or 0 . $date.


Here's a slower (execution-wise) but easier to read version:

$timestamp = strtotime(str_replace(/, /01/, strlen($date) == 6 ? 
0$date : $date));


Where I just did the concatenation inside a string, which I find easier 
to read.


All these examples assume that your date is in a fixed format, namely 
mm/. However, the last three should properly handle 09/2006, because 
they won't add a second zero to that. So that should work either way.


Regards, Adam Zey.

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



[PHP] Re: Date addition problem

2006-03-29 Thread David Robley
Adrian Bruce wrote:

 Hi
 
 I am having an unusual problem when trying to calculate dates in advance
 from a start date.  the code below shows a loop where by on each run an
 increasing number of weeks is added to the start date, this works as
 expected up untill the 8th time where for some reason it produces
 01-11-05 instead of 02-11-05.  I am at a loss as to why this would
 happen when it works perfectly for all the other dates.  where am i
 going wrong?
 
 [snip]
 
 ?php
 echoh1 date test/h1;
 $start = 05-09-07;
 $start = explode('-',$start);
 $startmk = mktime(0,0,0,$start[1],$start[2],$start[0]);
 $startdate = date('d-m-y',$startmk);
 
 for($i=0;$i10;$i++){
 $nextdate = date('d-m-y',$startmk + ($i*604800));
 echoh1$i:  $startdate -- -- --$nextdate/h1;
 }
 ?
 
 OUTPUT:
 
 0: 07-09-05 -- -- --07-09-05
 1: 07-09-05 -- -- --14-09-05
 2: 07-09-05 -- -- --21-09-05
 3: 07-09-05 -- -- --28-09-05
 4: 07-09-05 -- -- --05-10-05
 5: 07-09-05 -- -- --12-10-05
 6: 07-09-05 -- -- --19-10-05
 7: 07-09-05 -- -- --26-10-05
 8: 07-09-05 -- -- --01-11-05
 9: 07-09-05 -- -- --08-11-05
 
 [/snip]
 
 Thanks a lot
 
 Ade

Does daylight saving start or finish in that range of dates? If so, using 0
as the hour argument to mktime may give you the odd result you are seeing.
Try say 2 as the hour argument and see what happens .



Cheers
-- 
David Robley

The guy who writes all those bumper stickers HATES New York.
Today is Prickle-Prickle, the 16th day of Discord in the YOLD 3172. 

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



[PHP] Re: Date Question

2006-03-17 Thread João Cândido de Souza Neto
select date_format(date,%d/%m/%y) as date from table

It'll show in 17/03/06 format

select date_format(date,%d/%m/%Y) as date from table

It'll show in 17/03/2006 format


Tom Chubb wrote:

 Please can you help me. I've created a page where problems are posted into
 a database and I am using the datetime format in MySQL and trying to find
 the best way to display it in the 17/03/06 format.
 I've found a way of doing it (so you don't think I haven't googled, RTFM)
 but don't think it's the best way.
 Any help would be appreciated.
 
 (Current Code:)
 
 ?php
 $datestr = $row_rsSnags['date'];
 $arr1 = str_split($datestr, 2);
 echo $arr1 [2];
 echo /;
 echo $arr1 [1];
 echo /;
 echo $arr1 [0];
 //  echo $row_rsSnags['date'];
 ?

-- 
---
João Cândido de Souza Neto
Web Developer

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



Re: [PHP] Re: Date Question [SOLVED]

2006-03-17 Thread Tom Chubb
Thanks guys.

On 17/03/06, João Cândido de Souza Neto [EMAIL PROTECTED] wrote:

 select date_format(date,%d/%m/%y) as date from table

 It'll show in 17/03/06 format

 select date_format(date,%d/%m/%Y) as date from table

 It'll show in 17/03/2006 format


 Tom Chubb wrote:

  Please can you help me. I've created a page where problems are posted
 into
  a database and I am using the datetime format in MySQL and trying to
 find
  the best way to display it in the 17/03/06 format.
  I've found a way of doing it (so you don't think I haven't googled,
 RTFM)
  but don't think it's the best way.
  Any help would be appreciated.
 
  (Current Code:)
 
  ?php
  $datestr = $row_rsSnags['date'];
  $arr1 = str_split($datestr, 2);
  echo $arr1 [2];
  echo /;
  echo $arr1 [1];
  echo /;
  echo $arr1 [0];
  //  echo $row_rsSnags['date'];
  ?

 --
 ---
 João Cândido de Souza Neto
 Web Developer

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




--
Tom Chubb
[EMAIL PROTECTED]
07915 053312


[PHP] Re: Date question

2006-02-24 Thread William Stokes
Yep. Nevermind...

(and back to sleep)

William Stokes [EMAIL PROTECTED] kirjoitti 
viestissä:[EMAIL PROTECTED]
 Hello,

 I have a datetime column in MySQL DB. How can I match to that column from 
 php code if I only have the date information available.

 2006-02-24 12:00:00  against2006-02-24

 This might be more SQL question sorry about that.

 Thanks
 -Will 

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



[PHP] Re: date processing needed in form

2006-01-03 Thread Manuel Lemos

Hello,

on 01/03/2006 06:41 PM Sue said the following:
I need to create a form that allows the user to select a Month, Day and 
Year.  I am also new to PHP and am wondering if there is a way for me to 
display the contents of the Select list box (for the Day) based on the Month 
that is selected (and Year), so that the valid number of days for the month 
( year?) displays.  For all of our other forms, we use CGI to handle our 
standard forms validation, and was hoping to handle more complex validation 
within PHP prior to sending the entire contents of my form to our standard 
CGI validation routine.  I know that I could use the Checkdate function once 
the entire date is selected, but thought there might be an easier/more 
efficient way of handling this and also not sure how to reference Checkdate 
prior to Submitting my form to the CGI routine.  I also was not sure if this 
was something that is handled easier using Javascript?  Any help/examples, 
etc. would be greatly appreciated!


You may want to try this forms generation and validation class. It comes 
with a calendar date plug-in that does exactly what you want.


It lets you choose a date using several text or select fields and it can 
validate the date that you choose using special Javascript code 
generated by the  plug-in. If you want, it can also restrict the range 
of accepted dates, like since a given date or no later than another date.


The plug-in class validates either on the client side with Javascript or 
server side with PHP. You do not need to know any Javascript to use this.


http://www.phpclasses.org/formgeneration


Here is a screen shot:

http://www.phpclasses.org/browse/file/8245.html


Here is an example page:

http://www.phpclasses.org/browse/view/html/file/6799/name/test_date_input_page.html

--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



[PHP] Re: date processing needed in form

2006-01-03 Thread Jerry Kita

Sue wrote:

Hello -

I need to create a form that allows the user to select a Month, Day and 
Year.  I am also new to PHP and am wondering if there is a way for me to 
display the contents of the Select list box (for the Day) based on the Month 
that is selected (and Year), so that the valid number of days for the month 
( year?) displays.  For all of our other forms, we use CGI to handle our 
standard forms validation, and was hoping to handle more complex validation 
within PHP prior to sending the entire contents of my form to our standard 
CGI validation routine.  I know that I could use the Checkdate function once 
the entire date is selected, but thought there might be an easier/more 
efficient way of handling this and also not sure how to reference Checkdate 
prior to Submitting my form to the CGI routine.  I also was not sure if this 
was something that is handled easier using Javascript?  Any help/examples, 
etc. would be greatly appreciated!


Thanks!!
Sue 
For what it's worth I use JavaScript for validation prior to the form 
being submitted. It's faster and doesn't use any network resources. If 
you do validity checking at the browser using JavaScript ... then when 
the form is submitted I'd let it go straight through to your standard 
forms validation program ... I wouldn't even involve PHP.


--
Jerry Kita

http://www.salkehatchiehuntersville.com

email: [EMAIL PROTECTED]

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



[PHP] Re: date of file?

2005-09-11 Thread Michelle Konzack
Am 2005-09-11 03:08:22, schrieb [EMAIL PROTECTED]:
 In addition to reading the names of the files in a directory, I also
 need to read the date the file was modified. 

filemtime()

Greetings
Michelle

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
Michelle Konzack   Apt. 917  ICQ #328449886
   50, rue de Soultz MSM LinuxMichi
0033/3/8845235667100 Strasbourg/France   IRC #Debian (irc.icq.com)


signature.pgp
Description: Digital signature


[PHP] Re: date field

2005-08-11 Thread John Taylor-Johnston

Thanks Ben!
John

Ben Ramsey wrote:


In PHP, you could do something like:

$updated  = strtotime($db_result['updated']);
$one_year_ago = strtotime('-1 year');

if ($updated  $one_year_ago) {
// updated date is older than a year ago
}


John Taylor-Johnston wrote:

I have a field 'updated' How can I tell if the date is older than 1 
year ago (or should I think of 365 days)?


`updated` date NOT NULL default '1999-12-12'

I've looked at: http://ca3.php.net/manual/en/function.getdate.php

Thanks,
John






--
John Taylor-Johnston
-
If it's not Open Source, it's Murphy's Law.

 ' ' 'Collège de Sherbrooke:
ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
   - 819-569-2064

 °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
/(_)\  Université de Sherbrooke
 ^ ^   http://compcanlit.ca/ T: 819.569.2064

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



[PHP] Re: date field

2005-08-10 Thread Ben Ramsey

In PHP, you could do something like:

$updated  = strtotime($db_result['updated']);
$one_year_ago = strtotime('-1 year');

if ($updated  $one_year_ago) {
// updated date is older than a year ago
}


John Taylor-Johnston wrote:
I have a field 'updated' How can I tell if the date is older than 1 year 
ago (or should I think of 365 days)?


`updated` date NOT NULL default '1999-12-12'

I've looked at: http://ca3.php.net/manual/en/function.getdate.php

Thanks,
John



--
Ben Ramsey
http://benramsey.com/

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



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() reporting wrong on OS X server intermittently

2005-02-17 Thread Jason Barnett
Rowan Hick wrote:
...
 
 Has anyone out there seen weird problems like this before ?
 
 Many Thanks, 
 Rowan

The other suggestions are good.  If they don't pan out, check to see if
you use the function strtotime().  It has been buggy in a few versions
of PHP and may not be acting properly in your build...

http://www.php.net/manual/en/function.strtotime.php

-- 
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


[PHP] Re: Date Update

2005-02-04 Thread Jason Barnett
Adi Pramadi wrote:
Dear Friends,
I'm new in PHP programing, and i need a way to add date in php.
here is the sample
If today is 29/01/2005 (dd/mm/yy)
and i need to make an apointment for another 10 days
the date recorded sould be 08/02/2005 and not 39/01/2005
is there a way to do it in just like in asp (add date) ?
One of several ways to do it:
http://www.php.net/manual/en/function.strtotime.php
?php
echo strtotime(+1 week 3 days 4 hours 2 seconds), \n;
?
Regards,
Adi

--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Re: Date()

2005-01-17 Thread Steve Buehler
At 08:33 PM 1/15/2005, you wrote:
Torsten,
Whatever the combination, it echos February 02-2005brFebruary 
02-2005brFebruary 02-2005. What is wrong with it?

  ?php
  $week5 = 2005-02-14;
  $firstDayTs = strtotime($week5);
  $lastDayTs = $firstDayTs + (4 * 86400);
  echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . 
date('Y',$firstDayTs) .br;
  echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . 
date('Y',$lastDayTs) .br;
  ?

John
It is outputing what you are asking it to:
FA full textual representation of a month, such as January or March
mNumeric representation of a month, with leading zeros
YA full numeric representation of a year, 4 digits
This is all documented at: http://us2.php.net/manual/en/function.date.php
First you are asking for the Month as a name, then the month as a number 
then the year as a number.  If you made $week5=2005-12-31 it would give you 
the following output:
December 12-2005brDecember 12-2006br
If you are wanting to make it echo February 14-18, then check out the 3rd 
echo statement in the below example.

?php
  $week5 = 2005-02-14;
  $firstDayTs = strtotime($week5);
  $lastDayTs = $firstDayTs + (4 * 86400);
  echo date('F', $firstDayTs) . ' ' . date('d', $firstDayTs) . '-' . 
date('Y',$firstDayTs) .br\n;
  echo date('F', $lastDayTs) . ' ' . date('d', $lastDayTs) . '-' . 
date('Y',$lastDayTs) .br\n;
  echo date('F', $lastDayTs) . ' ' . date('d', $firstDayTs) . '-' . 
date('d',$lastDayTs) .br\n;
echo \n;
  ?
Now, the problem with that is that if your $week5=2005-02-18 then your 
results will be wrongunless this is what you want, but the answer will 
be February 28-04.  You are outputing the Month from $week5, the day from 
$week5 and the day+4 of $week5 which takes it into the next month.

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


[PHP] Re: Date()

2005-01-15 Thread Torsten Roehr

John Taylor-Johnston [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I might be doing this backwards, but how do I extract the date from $week5
and display $week5 + 4 days.  I would like to create a function so when I
pass

 echo displaydate($week5);

 it echos February 14-18

 $week0 = 2005-01-10;
 $week1 = 2005-01-17;
 $week2 = 2005-01-24;
 $week3 = 2005-01-31;
 $week4 = 2005-02-07;
 $week5 = 2005-02-14;
 $week6 = 2005-02-21;
 $week7 = 2005-02-28;

 `Doable´? Easy enough to learn how to do?

 John

Hi John,

// convert your data to a timestamp:
$firstDayTs = strtotime($week5);

// add 4 days
$lastDayTs = $firstDayTs + (4 * 86400);

echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . date('m',
$lastDayTs);

Not tested. Maybe there's an easier way to do this.

Regards, Torsten Roehr


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



[PHP] Re: Date()

2005-01-15 Thread John Taylor-Johnston
Don't know where my other post went, but I corrected it:

  echo date('F', $firstDayTs) . ' ' . date('d', $firstDayTs) . '-' . 
date('Y',$firstDayTs)
  echo date('F', $firstDayTs) . ' ' . date('d', $lastDayTs) . '-' . 
date('Y',$firstDayTs)

Thanks,
John

Torsten Roehr wrote:

 John Taylor-Johnston [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  I might be doing this backwards, but how do I extract the date from $week5
 and display $week5 + 4 days.  I would like to create a function so when I
 pass
 
  echo displaydate($week5);
 
  it echos February 14-18
 
  $week0 = 2005-01-10;
  $week1 = 2005-01-17;
  $week2 = 2005-01-24;
  $week3 = 2005-01-31;
  $week4 = 2005-02-07;
  $week5 = 2005-02-14;
  $week6 = 2005-02-21;
  $week7 = 2005-02-28;
 
  `Doable´? Easy enough to learn how to do?
 
  John

 Hi John,

 // convert your data to a timestamp:
 $firstDayTs = strtotime($week5);

 // add 4 days
 $lastDayTs = $firstDayTs + (4 * 86400);

 echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . date('m',
 $lastDayTs);

 Not tested. Maybe there's an easier way to do this.

 Regards, Torsten Roehr

--
John Taylor-Johnston
-
If it's not Open Source, it's Murphy's Law.

 '''Collège de Sherbrooke:
 ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
  - 819-569-2064

  °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
 /(_)\  Université de Sherbrooke
  ^ ^   http://compcanlit.ca/ T: 819.569.2064

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



[PHP] Re: Date()

2005-01-15 Thread John Taylor-Johnston
Torsten,
Whatever the combination, it echos February 02-2005brFebruary 
02-2005brFebruary 02-2005. What is wrong with it?

  ?php
  $week5 = 2005-02-14;
  $firstDayTs = strtotime($week5);
  $lastDayTs = $firstDayTs + (4 * 86400);
  echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . 
date('Y',$firstDayTs) .br;
  echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . 
date('Y',$lastDayTs) .br;
  ?

John



Roehr wrote:

 John Taylor-Johnston [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  I might be doing this backwards, but how do I extract the date from $week5
 and display $week5 + 4 days.  I would like to create a function so when I
 pass
 
  echo displaydate($week5);
 
  it echos February 14-18
 
  $week0 = 2005-01-10;
  $week1 = 2005-01-17;
  $week2 = 2005-01-24;
  $week3 = 2005-01-31;
  $week4 = 2005-02-07;
  $week5 = 2005-02-14;
  $week6 = 2005-02-21;
  $week7 = 2005-02-28;
 
  `Doable´? Easy enough to learn how to do?
 
  John

 Hi John,

 // convert your data to a timestamp:
 $firstDayTs = strtotime($week5);

 // add 4 days
 $lastDayTs = $firstDayTs + (4 * 86400);

 echo date('F', $firstDayTs) . ' ' . date('m', $firstDayTs) . '-' . date('m',
 $lastDayTs);

 Not tested. Maybe there's an easier way to do this.

 Regards, Torsten Roehr

--
John Taylor-Johnston
-
If it's not Open Source, it's Murphy's Law.

 '''Collège de Sherbrooke:
 ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
  - 819-569-2064

  °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
 /(_)\  Université de Sherbrooke
  ^ ^   http://compcanlit.ca/ T: 819.569.2064

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



[PHP] Re: Date-development stalled?

2005-01-02 Thread Matthew Weier O'Phinney
* Tmp [EMAIL PROTECTED]:
 It seems that development of Pear::Date has stalled. The package does has
 some major bugs when used with php5 - both in the main Date class and in
 Date_Span. There has been filled a bug report as early as september
 2004, but no fix has been made yet and no response from a developer, other
 than setting the verified-flag, has been made.

 Only solution has been to extend the classes and reimplement fixed
 versions of the methods. This is clearly not an optimal way of doing it.
 However, the bugs are easy to fix and I would happily do it - if just I
 could get in touch with the developers... (It's a matter of manually
 cloning function arguments of type object).

 What to do?

Subscribe to the pear-dev list, find out if any work is being done on
it, and, if not, volunteer to take over maintenance.

-- 
Matthew Weier O'Phinney   | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org

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



[PHP] Re: Date Conversions?

2004-11-15 Thread Matthew Weier O'Phinney
* Robert Sossomon [EMAIL PROTECTED]:
 I have a date in format YY-MM-DD in a MySQL table.  I need to pull it back to 
 display it in either format: MM-DD-YY or Month Day, Year format.

 I can't figure out how to write the query to do it, and am not sure
 how to make PHP just parse the one given and dump it back out in the
 way I need it.  Any suggestions?

http://php.net/strtotime

Specifically, try the following:

// $date is the date as pulled from the MySQL table
$convertedDate = date(m-d-y, strtotime($date));

-- 
Matthew Weier O'Phinney   | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org

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



Re: [PHP] Re: Date Conversions?

2004-11-15 Thread Robert Sossomon
Matthew Weier O'Phinney is quoted as saying on 11/15/2004 3:01 PM:
* Robert Sossomon [EMAIL PROTECTED]:
SNIP
http://php.net/strtotime
Specifically, try the following:
// $date is the date as pulled from the MySQL table
$convertedDate = date(m-d-y, strtotime($date));
Here's what I wound up using, in case anyone else comes across the same 
dilemma:
$Date = $Quote['Date'];
$EDate = date(M d, Y,strtotime($Date));

--
Robert Sossomon, Business and Technology Application Technician
4-H Youth Development Department
200 Ricks Hall, Campus Box 7606
N.C. State University
Raleigh NC 27695-7606
Phone: 919/515-8474
Fax:   919/515-7812
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Date and time

2004-08-11 Thread Aidan Lister
That's a mysql timestamp, if you want to manipulate dates in PHP you'll need
to use unix timestamps.

You have a couple of options,
select unix_timestamp(myFld) as myFld from myTbl

Then just add 60*60*24*7 to it.

Or, parse it with:
function convert_timestamp ($timestamp)
{
   $timestring = substr($timestamp,0,8). .
 substr($timestamp,8,2).:.
 substr($timestamp,10,2).:.
 substr($timestamp,12,2);

   return strtotime($timestring);
}


Diff Fannehh [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 I have this date in timestamp format:

 $a= 20040810114155;

 I want to add 7 days to this date. How can i do that?

 Thanks



 

 Home, no matter how far...
 http://www.home.ro

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



[PHP] Re: Date and time

2004-08-11 Thread Aidan Lister
There was a little mistake in the code I posted before, try this one:

http://aidan.dotgeek.org/lib/?file=function.convert_timestamp.php


Diff Fannehh [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 I have this date in timestamp format:

 $a= 20040810114155;

 I want to add 7 days to this date. How can i do that?

 Thanks



 

 Home, no matter how far...
 http://www.home.ro

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



Re: [PHP] Re: Date and time

2004-08-11 Thread Matthew Sims
 There was a little mistake in the code I posted before, try this one:

 http://aidan.dotgeek.org/lib/?file=function.convert_timestamp.php


 Diff Fannehh [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Hi,

 I have this date in timestamp format:

 $a= 20040810114155;

 I want to add 7 days to this date. How can i do that?

 Thanks



Isn't it considered faster to let the database do the conversion to Unix
Timestamp?

-- 
--Matthew Sims
--http://killermookie.org

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



[PHP] Re: date difference

2004-07-15 Thread Torsten Roehr
John Meyer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hello,
 Is there a function to determine the difference between two dates?  I am
 asking so I can do some date verification for COPA.

Convert your dates to timestamps which will be 10-digit integers (the time
since 1.1.1970 in seconds) you can then substract/add them like normal
numbers.

$date = '2004-07-15 01:00:00';
$date2 = '2004-07-15 02:00:00';
$timestamp = strtotime($date);
$timestamp2 = strtotime($date2);

echo $timestamp2 - $timestamp1; // will output 3600 (seconds)

Hope this helps. Regards,

Torsten Roehr

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



[PHP] Re: Date Diff function

2004-06-28 Thread Torsten Roehr
Richard Davey [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi all,

 Does anyone have a date-diff function in PHP that *doesn't* use Unix
 time stamps? I need to calculate differences between two date values,
 but the range well exceeds that which date supports on our server.

 Best regards,

Hi Richard,

take a look at PEAR's Date package:
http://pear.php.net/package/Date

Regards,

Torsten Roehr

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



[PHP] Re: Date Select

2004-06-25 Thread pete M
select * from table where week(date_field) = ( week(now()) -1 )
Tom Chubb wrote:
How can I query a MySQL table to get the latest results from a date field?
Basically, I am inserting several records at a time at the end of each week.
I want to have a page that displays the results for the last week only.
The date format in the field is -MM-DD
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Date Select

2004-06-25 Thread Gerben
select * from table where TO_DAYS(date_field)  ( TO_DAYS(NOW()) -7 )

this will give the entries of the last 7 days (and the ones that are in the
future)

Tom Chubb [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 How can I query a MySQL table to get the latest results from a date field?
 Basically, I am inserting several records at a time at the end of each
week.
 I want to have a page that displays the results for the last week only.
 The date format in the field is -MM-DD


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



[PHP] Re: Date Function - Empty Value

2004-05-20 Thread Gabe
Torsten Roehr wrote:
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Torsten Roehr wrote:

Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Torsten Roehr wrote:

Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Environment:
PHP 4.3.6
Access DB
W2K IIS 5
I'm trying to store a date in a date/time field using the short date
format ( m/d/ ).  For some reason it won't let me post an empty
value to that field in the DB.  I've tried using empty quotes (  )
or
NULL and I always get a datatype mismatch sql error.  So then I just
tried submitting a date that will never be used ( e.g. 1/1/ ).
That
works, but then when I try to read the date out of the field in the DB
and format it using the date() function in PHP it doesn't display
anything (which is fine with me).  I read up on the date function on
the
PHP website and valid dates are limited from 01-01-1970 to 19-01-2038
on
windows machines.  So that explains why the function returns nothing.
So, I guess my question is this:  Is what I'm doing technically ok
(using a date that's not in the valid range)?  Or does anyone know of
an
empty date value that I can submit to the DB?
Thanks!

NULL should work if you have allowed it for the column when creating
the
table. Can you post your table structure?
Regards, Torsten
Well, I would, but I can't seem to figure out how to export just the
structure out of access.  Wouldn't NULL be allowed by default?

This command should show you the table structure:
SHOW CREATE TABLE tablename
Please post the output.
regards, Torsten

Sorry Torsten, but you'll have to forgive my lack of understanding.
Where should I put that command in?
Thanks for you patience.

In the mysql command line, if possible or if you're using phpMyAdmin. Should
also work with mysql_query() in a php script and echoing out the result. Do
you know how to do this?
Regards, Torsten
I'm using Microsoft Access for my database not MySQL.  Does that change 
what I need to do?

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


[PHP] Re: Date Function - Empty Value

2004-05-20 Thread Torsten Roehr
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Torsten Roehr wrote:
  Gabe [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 Torsten Roehr wrote:
 
 
 Gabe [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
 
 Torsten Roehr wrote:
 
 
 
 Gabe [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
 
 
 Environment:
 PHP 4.3.6
 Access DB
 W2K IIS 5
 
 
 I'm trying to store a date in a date/time field using the short date
 format ( m/d/ ).  For some reason it won't let me post an empty
 value to that field in the DB.  I've tried using empty quotes (  )
 
  or
 
 NULL and I always get a datatype mismatch sql error.  So then I just
 tried submitting a date that will never be used ( e.g. 1/1/ ).
 
  That
 
 works, but then when I try to read the date out of the field in the
DB
 and format it using the date() function in PHP it doesn't display
 anything (which is fine with me).  I read up on the date function on
 
  the
 
 PHP website and valid dates are limited from 01-01-1970 to
19-01-2038
 
  on
 
 windows machines.  So that explains why the function returns
nothing.
 
 So, I guess my question is this:  Is what I'm doing technically ok
 (using a date that's not in the valid range)?  Or does anyone know
of
 
  an
 
 empty date value that I can submit to the DB?
 
 Thanks!
 
 
 NULL should work if you have allowed it for the column when creating
 
  the
 
 table. Can you post your table structure?
 
 Regards, Torsten
 
 Well, I would, but I can't seem to figure out how to export just the
 structure out of access.  Wouldn't NULL be allowed by default?
 
 
 This command should show you the table structure:
 SHOW CREATE TABLE tablename
 
 Please post the output.
 
 regards, Torsten
 
 
 Sorry Torsten, but you'll have to forgive my lack of understanding.
 Where should I put that command in?
 
 Thanks for you patience.
 
 
  In the mysql command line, if possible or if you're using phpMyAdmin.
Should
  also work with mysql_query() in a php script and echoing out the result.
Do
  you know how to do this?
 
  Regards, Torsten

 I'm using Microsoft Access for my database not MySQL.  Does that change
 what I need to do?

I'm not familiar with Access but should have an option or specific view to
show you the table structure. Look at the Access program help for something
like that.

Regards, Torsten

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



Re: [PHP] Re: Date Function - Empty Value

2004-05-20 Thread Mark Pecaut
On Thu, May 20, 2004 at 12:28:00PM -0400, Gabe wrote:
 I'm trying to store a date in a date/time field using the short date
 format ( m/d/ ).  For some reason it won't let me post an empty
 value to that field in the DB.  I've tried using empty quotes (  )
 
 I'm using Microsoft Access for my database not MySQL.  Does that change 
 what I need to do?

Access delimits dates with '#' hash marks.  Try something like:

UPDATE tablename SET date_field=#9/30/2003# WHERE foo='bar';

or

UPDATE tablename SET date_field=NULL WHERE foo='bar';

if you want to make that field null.  If it complains when you try to
set it NULL and you want it to be null, put 'No' for 'Required' for that
field in Design View.

-Mark

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



Re: [PHP] Re: Date Function - Empty Value

2004-05-20 Thread Gabe
Mark Pecaut wrote:
On Thu, May 20, 2004 at 12:28:00PM -0400, Gabe wrote:
I'm trying to store a date in a date/time field using the short date
format ( m/d/ ).  For some reason it won't let me post an empty
value to that field in the DB.  I've tried using empty quotes (  )
I'm using Microsoft Access for my database not MySQL.  Does that change 
what I need to do?

Access delimits dates with '#' hash marks.  Try something like:
UPDATE tablename SET date_field=#9/30/2003# WHERE foo='bar';
or
UPDATE tablename SET date_field=NULL WHERE foo='bar';
if you want to make that field null.  If it complains when you try to
set it NULL and you want it to be null, put 'No' for 'Required' for that
field in Design View.
-Mark
I'll give those a try.  Thanks for the tips.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Date Function - Empty Value

2004-05-20 Thread Gabe
Torsten Roehr wrote:
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Torsten Roehr wrote:
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Torsten Roehr wrote:

Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Torsten Roehr wrote:


Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


Environment:
PHP 4.3.6
Access DB
W2K IIS 5
I'm trying to store a date in a date/time field using the short date
format ( m/d/ ).  For some reason it won't let me post an empty
value to that field in the DB.  I've tried using empty quotes (  )
or

NULL and I always get a datatype mismatch sql error.  So then I just
tried submitting a date that will never be used ( e.g. 1/1/ ).
That

works, but then when I try to read the date out of the field in the
DB
and format it using the date() function in PHP it doesn't display
anything (which is fine with me).  I read up on the date function on
the

PHP website and valid dates are limited from 01-01-1970 to
19-01-2038
on

windows machines.  So that explains why the function returns
nothing.
So, I guess my question is this:  Is what I'm doing technically ok
(using a date that's not in the valid range)?  Or does anyone know
of
an

empty date value that I can submit to the DB?
Thanks!

NULL should work if you have allowed it for the column when creating
the

table. Can you post your table structure?
Regards, Torsten
Well, I would, but I can't seem to figure out how to export just the
structure out of access.  Wouldn't NULL be allowed by default?

This command should show you the table structure:
SHOW CREATE TABLE tablename
Please post the output.
regards, Torsten

Sorry Torsten, but you'll have to forgive my lack of understanding.
Where should I put that command in?
Thanks for you patience.

In the mysql command line, if possible or if you're using phpMyAdmin.
Should
also work with mysql_query() in a php script and echoing out the result.
Do
you know how to do this?
Regards, Torsten
I'm using Microsoft Access for my database not MySQL.  Does that change
what I need to do?

I'm not familiar with Access but should have an option or specific view to
show you the table structure. Look at the Access program help for something
like that.
Regards, Torsten
After looking carefully through the table structure, it does allow NULL 
values.  So maybe I'm not passing it correctly to the variables in the 
SQL.  I thought I was

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


[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Torsten Roehr
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Environment:
 PHP 4.3.6
 Access DB
 W2K IIS 5


 I'm trying to store a date in a date/time field using the short date
 format ( m/d/ ).  For some reason it won't let me post an empty
 value to that field in the DB.  I've tried using empty quotes (  ) or
 NULL and I always get a datatype mismatch sql error.  So then I just
 tried submitting a date that will never be used ( e.g. 1/1/ ).  That
 works, but then when I try to read the date out of the field in the DB
 and format it using the date() function in PHP it doesn't display
 anything (which is fine with me).  I read up on the date function on the
 PHP website and valid dates are limited from 01-01-1970 to 19-01-2038 on
 windows machines.  So that explains why the function returns nothing.

 So, I guess my question is this:  Is what I'm doing technically ok
 (using a date that's not in the valid range)?  Or does anyone know of an
 empty date value that I can submit to the DB?

 Thanks!

NULL should work if you have allowed it for the column when creating the
table. Can you post your table structure?

Regards, Torsten

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



[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Gabe
Torsten Roehr wrote:
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Environment:
PHP 4.3.6
Access DB
W2K IIS 5
I'm trying to store a date in a date/time field using the short date
format ( m/d/ ).  For some reason it won't let me post an empty
value to that field in the DB.  I've tried using empty quotes (  ) or
NULL and I always get a datatype mismatch sql error.  So then I just
tried submitting a date that will never be used ( e.g. 1/1/ ).  That
works, but then when I try to read the date out of the field in the DB
and format it using the date() function in PHP it doesn't display
anything (which is fine with me).  I read up on the date function on the
PHP website and valid dates are limited from 01-01-1970 to 19-01-2038 on
windows machines.  So that explains why the function returns nothing.
So, I guess my question is this:  Is what I'm doing technically ok
(using a date that's not in the valid range)?  Or does anyone know of an
empty date value that I can submit to the DB?
Thanks!

NULL should work if you have allowed it for the column when creating the
table. Can you post your table structure?
Regards, Torsten
Well, I would, but I can't seem to figure out how to export just the 
structure out of access.  Wouldn't NULL be allowed by default?

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


[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Matt Matijevich
[snip]
Well, I would, but I can't seem to figure out how to export just the 
structure out of access.  Wouldn't NULL be allowed by default?
[/snip]

Do you have access to the mdb file?  If you do you can just go into
design view of the table to find out the data definitions.

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



Re: [PHP] Re: Date Function - Empty Value

2004-05-19 Thread Gabe
Matt Matijevich wrote:
[snip]
Well, I would, but I can't seem to figure out how to export just the 
structure out of access.  Wouldn't NULL be allowed by default?
[/snip]

Do you have access to the mdb file?  If you do you can just go into
design view of the table to find out the data definitions.
I do have access to the mdb but there's no way for me to export the 
structure that I'm looking at so I can send it to other people.  Or do 
you know of a way?

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


[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Torsten Roehr
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Torsten Roehr wrote:

  Gabe [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 Torsten Roehr wrote:
 
 
 Gabe [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
 
 Environment:
 PHP 4.3.6
 Access DB
 W2K IIS 5
 
 
 I'm trying to store a date in a date/time field using the short date
 format ( m/d/ ).  For some reason it won't let me post an empty
 value to that field in the DB.  I've tried using empty quotes (  )
or
 NULL and I always get a datatype mismatch sql error.  So then I just
 tried submitting a date that will never be used ( e.g. 1/1/ ).
That
 works, but then when I try to read the date out of the field in the DB
 and format it using the date() function in PHP it doesn't display
 anything (which is fine with me).  I read up on the date function on
the
 PHP website and valid dates are limited from 01-01-1970 to 19-01-2038
on
 windows machines.  So that explains why the function returns nothing.
 
 So, I guess my question is this:  Is what I'm doing technically ok
 (using a date that's not in the valid range)?  Or does anyone know of
an
 empty date value that I can submit to the DB?
 
 Thanks!
 
 
 NULL should work if you have allowed it for the column when creating
the
 table. Can you post your table structure?
 
 Regards, Torsten
 
 Well, I would, but I can't seem to figure out how to export just the
 structure out of access.  Wouldn't NULL be allowed by default?
 
 
  This command should show you the table structure:
  SHOW CREATE TABLE tablename
 
  Please post the output.
 
  regards, Torsten


 Sorry Torsten, but you'll have to forgive my lack of understanding.
 Where should I put that command in?

 Thanks for you patience.

In the mysql command line, if possible or if you're using phpMyAdmin. Should
also work with mysql_query() in a php script and echoing out the result. Do
you know how to do this?

Regards, Torsten

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



[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Gabe
Torsten Roehr wrote:
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Torsten Roehr wrote:

Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Environment:
PHP 4.3.6
Access DB
W2K IIS 5
I'm trying to store a date in a date/time field using the short date
format ( m/d/ ).  For some reason it won't let me post an empty
value to that field in the DB.  I've tried using empty quotes (  ) or
NULL and I always get a datatype mismatch sql error.  So then I just
tried submitting a date that will never be used ( e.g. 1/1/ ).  That
works, but then when I try to read the date out of the field in the DB
and format it using the date() function in PHP it doesn't display
anything (which is fine with me).  I read up on the date function on the
PHP website and valid dates are limited from 01-01-1970 to 19-01-2038 on
windows machines.  So that explains why the function returns nothing.
So, I guess my question is this:  Is what I'm doing technically ok
(using a date that's not in the valid range)?  Or does anyone know of an
empty date value that I can submit to the DB?
Thanks!

NULL should work if you have allowed it for the column when creating the
table. Can you post your table structure?
Regards, Torsten
Well, I would, but I can't seem to figure out how to export just the
structure out of access.  Wouldn't NULL be allowed by default?

This command should show you the table structure:
SHOW CREATE TABLE tablename
Please post the output.
regards, Torsten

Sorry Torsten, but you'll have to forgive my lack of understanding. 
Where should I put that command in?

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


[PHP] Re: Date Function - Empty Value

2004-05-19 Thread Torsten Roehr
Gabe [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Torsten Roehr wrote:

  Gabe [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 Environment:
 PHP 4.3.6
 Access DB
 W2K IIS 5
 
 
 I'm trying to store a date in a date/time field using the short date
 format ( m/d/ ).  For some reason it won't let me post an empty
 value to that field in the DB.  I've tried using empty quotes (  ) or
 NULL and I always get a datatype mismatch sql error.  So then I just
 tried submitting a date that will never be used ( e.g. 1/1/ ).  That
 works, but then when I try to read the date out of the field in the DB
 and format it using the date() function in PHP it doesn't display
 anything (which is fine with me).  I read up on the date function on the
 PHP website and valid dates are limited from 01-01-1970 to 19-01-2038 on
 windows machines.  So that explains why the function returns nothing.
 
 So, I guess my question is this:  Is what I'm doing technically ok
 (using a date that's not in the valid range)?  Or does anyone know of an
 empty date value that I can submit to the DB?
 
 Thanks!
 
 
  NULL should work if you have allowed it for the column when creating the
  table. Can you post your table structure?
 
  Regards, Torsten

 Well, I would, but I can't seem to figure out how to export just the
 structure out of access.  Wouldn't NULL be allowed by default?

This command should show you the table structure:
SHOW CREATE TABLE tablename

Please post the output.

regards, Torsten

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



[PHP] Re: date()

2004-03-19 Thread Andre Cerqueira
is that all?

Khalid Judeh wrote:

hello all,
i am new to php, i am trying to call the date  function this way:
?php echo date(d/m/y); ?
and the result i get is: object18/03/04
any help would be appreciated
 


Khaled Jouda 

cell. phone: 0163-2382758 
fax: 1(801)439-1253 
alternative email: [EMAIL PROTECTED]
_

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: date()

2004-03-19 Thread Eric Gorr
Khalid Judeh wrote:

hello all,
i am new to php, i am trying to call the date  function this way:
?php echo date(d/m/y); ?
and the result i get is: object18/03/04
any help would be appreciated
hummm...very odd. I did the same thing and got:

19/03/04

Can you provide any more details? What version of PHP is being used?

(I would, of course, have seen: '18/03/04' if I had run this yesterday )

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


[PHP] Re: date() before 1 Jan 1970...

2004-03-08 Thread Ben Ramsey
Check out the manual:
http://www.php.net/strtotime
Theoretically, this should work:
$old_date = strtotime(January 1, 1903 18:11 pm);
echo date(Y-m-d H:i:s, $old_date);
But all that echoes is:
1969-12-31 18:59:59
On that manual page, you'll see the following note:

quote
Note:  The valid range of a timestamp is typically from Fri, 13 Dec 1901 
20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that 
correspond to the minimum and maximum values for a 32-bit signed 
integer.) Additionally, not all platforms support negative timestamps, 
therefore your date range may be limited to no earlier than the Unix 
epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on 
Windows, some Linux distributions, and a few other operating systems.
/quote

I'm not sure whether there is a good work-around for converting that 
string to a timestamp; however, this does work and will produce the 
desired results:

$old_date = mktime(0, 11, 18, 1, 1, 1903);
echo date(Y-m-d H:i:s, $old_date);
Adwinwijaya wrote:

Hello php-general,

  how to display date like Monday, 1 January 1903 18:11 pm in php ?
  (since the date() function only able to display date before 1970)
  (and why it only support date after 1 Jan 1970) ?
  thanks
--
Regards,
 Ben Ramsey
 http://benramsey.com
 http://www.phpcommunity.org/wiki/People/BenRamsey
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: date() before 1 Jan 1970...

2004-03-08 Thread Ben Ramsey
Ben Ramsey wrote:
$old_date = mktime(0, 11, 18, 1, 1, 1903);
echo date(Y-m-d H:i:s, $old_date);
Argh!  I had the numbers reversed.  It should be:
$old_date = mktime(18, 11, 0, 1, 1, 1903);
But you get the idea...

--
Regards,
 Ben Ramsey
 http://benramsey.com
 http://www.phpcommunity.org/wiki/People/BenRamsey
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: date functions

2004-02-25 Thread David Robley
In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 Hi,
 
 You might already be fed up with my posts but I'm a complete PHP newbie and find 
 these groups are the best way to learn! Anyway I have the database date in the 
 format: -mm-dd hh:mm:ss e.g. 2004-02-24 07:57:59 but when in some situations I 
 only want to show the user the date in the format dd-mm- what is the correct / 
 best php function to use for this purpose ?
 
 Cheers.
 
 Matt

If you are pulling the dates from mysql, you could use the DATE_FORMAT in 
mysql to present them in the required format.

-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

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



[PHP] Re: date

2004-02-20 Thread Lucian Cozma
date('Y-m-d', time()- 60*60*24);

You could also use mktime.

Regards,
Lucian

Madcat [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 hi there

 how do i make php give me yesterday's date?

 i tried

 date(Y-m-d)-1

 but if today would be the 1st of july (2004-07-01), yesterday would be 00.
 july (2004-07-00) according to that calculator.
 is there any way to make this one get it right? without any if-structures
if
 possible

 regards

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



Re: [PHP] Re: date

2004-02-20 Thread Richard Davey
 how do i make php give me yesterday's date?

 i tried

 date(Y-m-d)-1

LC date('Y-m-d', time()- 60*60*24);
LC You could also use mktime.

Someone has already advised you look at strtotime, but just incase you
haven't here is one way you can use it:

$yesterdays_timestamp = strtotime(-1 day);

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] Re: date() funtion language

2004-02-13 Thread André Cerqueira
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
ohhh
thanks hehe
Don Read wrote:
On 12-Feb-2004 André Cerqueira wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
i had problems with locale
i think its safer to make a dayname and monthname array, and use
getdate(), than build the string yourself


snip

//the follow should, but doesnt seem to work
//setlocale(LC_ALL, 'pt_BR');
//echo date('l, j de F de Y');
?


date() doesn't format according to locale but strftime() does:

setlocale(LC_ALL, 'pt_BR.ISO8859-1');
echo strftime('%A, %B %e %Y');
// output 'Quinta Feira, Fevereiro 12 2004'



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFALQ4vaxdA/5C8vH8RAullAKDRwh4XpJg/lbZymdgW2fI+C2XbHwCfT5E+
6kGxyTlAnBjWvZGy1XT5YSY=
=mYsa
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: date() funtion language

2004-02-13 Thread André Cerqueira
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
hmz...
i just tryed that... didnt work
tryed other locale strings, didnt work...
do i need something else to make it work?
running php4.3.4rc3 on windows


Don Read wrote:

On 12-Feb-2004 André Cerqueira wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
i had problems with locale
i think its safer to make a dayname and monthname array, and use
getdate(), than build the string yourself


snip

//the follow should, but doesnt seem to work
//setlocale(LC_ALL, 'pt_BR');
//echo date('l, j de F de Y');
?


date() doesn't format according to locale but strftime() does:

setlocale(LC_ALL, 'pt_BR.ISO8859-1');
echo strftime('%A, %B %e %Y');
// output 'Quinta Feira, Fevereiro 12 2004'



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFALQ73axdA/5C8vH8RAt+IAKCuAH1hlInsMdcwkNvFmJy119YC/ACg0uws
uvW3FtqgRSXl5VkOcPVgTls=
=3cMI
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: date() funtion language

2004-02-12 Thread Don Read

On 12-Feb-2004 André Cerqueira wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 i had problems with locale
 i think its safer to make a dayname and monthname array, and use
 getdate(), than build the string yourself
 

snip

 
 //the follow should, but doesnt seem to work
 //setlocale(LC_ALL, 'pt_BR');
 //echo date('l, j de F de Y');
 ?

date() doesn't format according to locale but strftime() does:

setlocale(LC_ALL, 'pt_BR.ISO8859-1');
echo strftime('%A, %B %e %Y');

// output 'Quinta Feira, Fevereiro 12 2004'



-- 
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

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



[PHP] Re: date() funtion language

2004-02-11 Thread André Cerqueira
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
i had problems with locale
i think its safer to make a dayname and monthname array, and use
getdate(), than build the string yourself
like:

?
$wdayname_array = array('Domingo', 'Segunda', 'Terça', 'Quarta',
'Quinta', 'Sexta', 'Sábado');
$monthname_array = array('Janeiro', 'Fevereiro', 'Março', 'Abril',
'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro',
'Dezembro');
function date_wrapper($format, $timestamp=NULL)
{
global $wdayname_array, $monthname_array;
if ($timestamp == NULL)
$timestamp = time();
$date = getdate($timestamp);
$wdayname = $wdayname_array[$date['wday']];
$monthname = $monthname_array[$date['mon']-1];
$format = str_replace(array('l', 'F'), array('\l', '\F'), $format);
$date = date($format, $timestamp);
$date = str_replace(array('\\l', '\\F'), array($wdayname, $monthname),
$date);
return $date;
}
echo date_wrapper('l, d \de F \de Y');

//the follow should, but doesnt seem to work
//setlocale(LC_ALL, 'pt_BR');
//echo date('l, j de F de Y');
?
this example may not work well with slashes... just wrote it hehe

tb sou brasileiro hehe (im brazillian too)

Thiago Pavesi wrote:

| Hello,
|
| Does any one knows how do I set my date() function to return the days
|  of the week and moth in my own language (brazilian portuguese)?
|
| Thanks,
|
| Thiago Pavesi
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFAKuWmaxdA/5C8vH8RAv7gAJ0WHvXC4beywQDTjQzz7KI0jLGfPACgjqgv
y/UzSg9ijyRx/UvWGi8dFXU=
=Wh2S
-END PGP SIGNATURE-
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Re: Date comparison

2004-02-04 Thread Michael Nolan
Burhan Khalid wrote:
BEOI 7308 wrote:

Hi

I want to substract $first_date to $second_date and print the result
this way : 

xx days, xx hours, xx minutes

i tried (strtotime($second_date)-strtotime($first_date)) but what i
get is a timestamp and i dont know what to do with it 

Is there already a function to print the result in a human readable
way ? 

Thx


http://www.php.net/date

I'm not sure that helps too much.  Subtracting unix timestamps will give 
the difference in seconds.  You can then use division and remainders to 
calculate the hours, minutes and seconds.

Michael

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


[PHP] Re: date for mysql

2003-10-17 Thread pete M
insert into table (date_created) values( now() )

;-)
pete
Diana Castillo wrote:

how can I format the current date and time so that I can insert it into a
mysql table with an insert query?
--
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 Validation, Kinda'

2003-08-21 Thread Scott Fletcher
I did similiar posting about finding the last day of the month last week and
got some response.  So, I'll just post some clipping from php.net for you.
If your machine support the php mktime() then you're in for luck.  You can
find more info about it at php.net with the function, date() and mktime().

--snip--

   //To find out the last day of the month
   echo date (M-d-Y, mktime (0,0,0,12,32,1997));

--snip--

Scott F.

Jay Blanchard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Howdy,

Has anyone written any date validation function or sequence. I have
looked around, but haven't found anything. I am cobbling togather
something, but was hoping to not have to re-invent the wheel. The date
is formatted MMDD and is input by the user;

$userCentury = substr($userDate, 0, 2); //must be 20 (no problem)
$userYear = substr($userDate, 2, 2); //must be 03 or better
$userMonth = substr($userDate, 4, 2); // 01-12
$userDay = substr($userDate, 6, 2); // 01-31

It doesn't matter if the month is 02 and they have entered 31 as the
day. If any one of the four conditions is not true it gives them a
warning. Anyone done this before?

Thanks!

Jay



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

2003-03-05 Thread Philip Hallstrom
Strip off the H:i:s part using explode() and use date() to get an
equivalent string for right now and if they match, today's the day.

On Wed, 5 Mar 2003, Sebastian wrote:

 I have a date field in mysql in this format: Y-m-d H:i:s

 I would like to echo Today if the date is today, can someone offer some
 help? Thanks.

 warm regards,
 Sebastian - [BBR] Gaming Clan
 http://www.broadbandreports.com


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



Re: [PHP] Re: Date Question.

2003-03-05 Thread Sebastian
can you give an example? I am stil learning :)

- Original Message -
From: Philip Hallstrom [EMAIL PROTECTED]


| Strip off the H:i:s part using explode() and use date() to get an
| equivalent string for right now and if they match, today's the day.
|
| On Wed, 5 Mar 2003, Sebastian wrote:
|
|  I have a date field in mysql in this format: Y-m-d H:i:s
| 
|  I would like to echo Today if the date is today, can someone offer
some
|  help? Thanks.


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



Re: [PHP] Re: Date Question.

2003-03-05 Thread Kevin Stone
He's recommending something like this..

$tmp = explode(' ', $date);
if (date(Y-m-d) == $tmp[0])  // date format -mm-dd
{
echo Today;
}

Seems like a reasonable solution to me.  Read the manual if you need more
information..
http://www.php.net/manual/en/function.explode.php
http://www.php.net/manual/en/function.date.php

- Kevin


- Original Message -
From: Sebastian [EMAIL PROTECTED]
To: Philip Hallstrom [EMAIL PROTECTED]
Cc: php list [EMAIL PROTECTED]
Sent: Wednesday, March 05, 2003 12:32 PM
Subject: Re: [PHP] Re: Date Question.


 can you give an example? I am stil learning :)

 - Original Message -
 From: Philip Hallstrom [EMAIL PROTECTED]


 | Strip off the H:i:s part using explode() and use date() to get an
 | equivalent string for right now and if they match, today's the day.
 |
 | On Wed, 5 Mar 2003, Sebastian wrote:
 |
 |  I have a date field in mysql in this format: Y-m-d H:i:s
 | 
 |  I would like to echo Today if the date is today, can someone offer
 some
 |  help? Thanks.


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

2003-03-05 Thread Sebastian
Thank you very much, That worked well.

warm regards,
Sebastian.

- Original Message -
From: Kevin Stone [EMAIL PROTECTED]
To: Sebastian [EMAIL PROTECTED]; Philip Hallstrom
[EMAIL PROTECTED]
Cc: php list [EMAIL PROTECTED]
Sent: Wednesday, March 05, 2003 2:38 PM
Subject: Re: [PHP] Re: Date Question.


| He's recommending something like this..
|
| $tmp = explode(' ', $date);
| if (date(Y-m-d) == $tmp[0])  // date format -mm-dd
| {
| echo Today;
| }
|
| Seems like a reasonable solution to me.  Read the manual if you need more
| information..
| http://www.php.net/manual/en/function.explode.php
| http://www.php.net/manual/en/function.date.php
|
| - Kevin
|
|
| - Original Message -
| From: Sebastian [EMAIL PROTECTED]
| To: Philip Hallstrom [EMAIL PROTECTED]
| Cc: php list [EMAIL PROTECTED]
| Sent: Wednesday, March 05, 2003 12:32 PM
| Subject: Re: [PHP] Re: Date Question.
|
|
|  can you give an example? I am stil learning :)
| 
|  - Original Message -
|  From: Philip Hallstrom [EMAIL PROTECTED]
| 
| 
|  | Strip off the H:i:s part using explode() and use date() to get an
|  | equivalent string for right now and if they match, today's the day.
|  |
|  | On Wed, 5 Mar 2003, Sebastian wrote:
|  |
|  |  I have a date field in mysql in this format: Y-m-d H:i:s
|  | 
|  |  I would like to echo Today if the date is today, can someone offer
|  some
|  |  help? Thanks.


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



[PHP] Re: date range assistance needed

2003-03-03 Thread Bobby Patel
I believe PHP and MySQL use two different definitions of the start of a time
stamp. One uses 1974 the other 1900 (I don't know exactly). If you echo
strtotime($attributes[startdate]) ,  UNIX_TIMESTAMP (datestamp)

Also, in your query you are looking for all headlines that have
strtotime($attributes[startdate]) ==  UNIX_TIMESTAMP (datestamp). you have
two strtotime($attributes[startdate]) but not an 'end date '



Charles Kline [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Here is my current query:

 $qAnnouncement =
 'SELECT id,headline
   FROM tbl_funding
 WHERE 1
 AND ((UNIX_TIMESTAMP (datestamp) = ' .
 strtotime($attributes[startdate]) . ') AND (UNIX_TIMESTAMP (datestamp)
 = ' . strtotime($attributes[startdate]) . ')) LIMIT 0, 30';

 Where datestamp is set in MySQL with a timestamp(14) and
 $attributes[startdate] and $attributes[enddate] are in the format
 mm/dd/

 My query does not return any results. I know there must be something
 wrong, can anyone point it out?

 Thanks,
 Charles




-- 
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, first of next month?

2003-02-27 Thread Bryan Koschmann - GKT
On Wed, 26 Feb 2003, Philip Hallstrom wrote:
|
|Use the w option of date() and loop through adding 86400 to $t until you
|get to a number between 1 and 5.
|
| w - day of the week, numeric, i.e. 0 (Sunday) to 6 (Saturday)


I may of gotten ahead of myself, but I tried it using if/else. Looks like
this:

$t = mktime(0,0,0,date('m')+1,1,date('Y'));
$expdate = date(l, F jS Y, $t);

$expdatenum = date(w, $t);

if ($expdatenum == 6) {
$rendate = date(l, F jS Y, strtotime($expdate +2 days));
} else {
$rendate = date(l, F jS Y, strtotime($expdate +1 day));
}


I'm not sure if it would be more inefficient or what, but it seems to work
(so far). I'm not too worried about efficiency because it will only run
once a month.

Thanks to everyone who replied! I appreciate all the help!

Bryan


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



[PHP] Re: date, first of next month?

2003-02-26 Thread Philip Hallstrom
 On Wed, 26 Feb 2003, 1LT John W. Holmes wrote:

 |You would think strtotime(first of next month) would work, but it doesn't.
 |This does:
 |
 |$t = mktime(0,0,0,date('m')+1,1,date('Y'));
 |
 |Gives you timestamp of first day, next month. Format accordingly with
 |date().

 Thats great, worked perfectly! Thank you very much :)

 Heres a tough one, is there such a say to now get the date of the first
 weekday after that date?

Use the w option of date() and loop through adding 86400 to $t until you
get to a number between 1 and 5.

 w - day of the week, numeric, i.e. 0 (Sunday) to 6 (Saturday)

-philip


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



[PHP] Re: Date/Time Logic

2003-02-19 Thread Philip Hallstrom
Store the timestamp of their first login to a database.  Also store the
number of days (3, 90, 365) that there account is valid.  Setup a script
to nightly go through the database and for any records where:

first_login_timstamp + number_of_days  right_now

is true invalidate their login and send notifications.

Pretty easy to do with the date/time functions in any database.  Of if you
can't use a database like that, store it all as numbers (timestamps -
number of seconds since 1970...) and just do the math with 86400 seconds
equalling one day.

good luck!

On Wed, 19 Feb 2003, Pushpinder Singh Garcha wrote:

 Hello  Everyone,

 My php/mysql application needs to keep track of the first time that a
 User logs on to the site. Afterwards the User should be allowed either
 3 days / 3 months/1 year of access to the site. Once the stipulated
 time period is over the system should invalidate the login of the user.
 The Admin/ User should get email notification about this. The
 notification part is easy the hard part to figure out is how to be able
 to keep and tab on the Time Period stipulated for a user.

 Thanks in advance
 Pushpinder Singh Garcha
 _
 Web Architect



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




[PHP] Re: date calculation

2003-02-16 Thread Fred Merritt
Qt,
	The easiest way is to convert your dates into a serial day number(i.e. 
the number of days that have elapsed between your date, and some 
arbitrary date in the dim and distant past - I think PHP uses 25th 
November, -4714).  There are some calendar functions in php that will do 
this for you.  Once you have your dates as a numeric offset, you can 
subtract them to get a the number of days between the dates, or you can 
add or subtract a number of days to get a new offset.  Once you have the 
new offset, there are reverse calendar functions in php, to convert your 
new offset back to a calendar date.

Check out the functions GregorianToJD(), and JDToGregorian(), in the 
Calendar functions of the PHP manual.  If you do not have access to the 
calendar functions in your version of php, there are also a couple of 
examples how to do one of the conversions written in PHP, in the user 
contributed notes of the manual.  There are also many published articles 
describing algorithms on how to do this.  I can remember implementing 
these functions in 1977(Not in PHP of course), from an article published 
in the journal of the ACM, in 1963.

Hope this helps. . . Fred

Qt wrote:
Dear Sirs,

How can I add or subtract two date easily. Is therea any lib or function
about this. I can not find any easy way in the manual

Best Regards





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




Re: [PHP] Re: date calculation

2003-02-16 Thread olinux
If you're using a database, it may be able to take
care of this for you. If you're using mysql:

6.3.4 Date and Time Functions
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Date_and_time_functions

olinux 


--- Fred Merritt [EMAIL PROTECTED] wrote:
 Qt,
   The easiest way is to convert your dates into a
 serial day number(i.e. 
 the number of days that have elapsed between your
 date, and some 
 arbitrary date in the dim and distant past - I think
 PHP uses 25th 
 November, -4714).  There are some calendar functions
 in php that will do 
 this for you.  Once you have your dates as a numeric
 offset, you can 
 subtract them to get a the number of days between
 the dates, or you can 
 add or subtract a number of days to get a new
 offset.  Once you have the 
 new offset, there are reverse calendar functions in
 php, to convert your 
 new offset back to a calendar date.
 
 Check out the functions GregorianToJD(), and
 JDToGregorian(), in the 
 Calendar functions of the PHP manual.  If you do not
 have access to the 
 calendar functions in your version of php, there are
 also a couple of 
 examples how to do one of the conversions written in
 PHP, in the user 
 contributed notes of the manual.  There are also
 many published articles 
 describing algorithms on how to do this.  I can
 remember implementing 
 these functions in 1977(Not in PHP of course), from
 an article published 
 in the journal of the ACM, in 1963.
 
 Hope this helps. . . Fred
 
 Qt wrote:
  Dear Sirs,
  
  How can I add or subtract two date easily. Is
 therea any lib or function
  about this. I can not find any easy way in the
 manual
  
  Best Regards
  

__
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

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




Re: [PHP] Re: date calculation

2003-02-16 Thread qt
No I am not using msql


Olinux [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 If you're using a database, it may be able to take
 care of this for you. If you're using mysql:

 6.3.4 Date and Time Functions

http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Dat
e_and_time_functions

 olinux


 --- Fred Merritt [EMAIL PROTECTED] wrote:
  Qt,
  The easiest way is to convert your dates into a
  serial day number(i.e.
  the number of days that have elapsed between your
  date, and some
  arbitrary date in the dim and distant past - I think
  PHP uses 25th
  November, -4714).  There are some calendar functions
  in php that will do
  this for you.  Once you have your dates as a numeric
  offset, you can
  subtract them to get a the number of days between
  the dates, or you can
  add or subtract a number of days to get a new
  offset.  Once you have the
  new offset, there are reverse calendar functions in
  php, to convert your
  new offset back to a calendar date.
 
  Check out the functions GregorianToJD(), and
  JDToGregorian(), in the
  Calendar functions of the PHP manual.  If you do not
  have access to the
  calendar functions in your version of php, there are
  also a couple of
  examples how to do one of the conversions written in
  PHP, in the user
  contributed notes of the manual.  There are also
  many published articles
  describing algorithms on how to do this.  I can
  remember implementing
  these functions in 1977(Not in PHP of course), from
  an article published
  in the journal of the ACM, in 1963.
 
  Hope this helps. . . Fred
 
  Qt wrote:
   Dear Sirs,
  
   How can I add or subtract two date easily. Is
  therea any lib or function
   about this. I can not find any easy way in the
  manual
  
   Best Regards
  

 __
 Do you Yahoo!?
 Yahoo! Shopping - Send Flowers for Valentine's Day
 http://shopping.yahoo.com



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




  1   2   >