Re: [PHP] mysql date question

2008-01-03 Thread Stut

Adam Williams wrote:
select date_format('contract.length_start', '%m-%d-%Y') as length_start 
from contract where user_id = 1;


This has nothing to do with PHP, but the first parameter to date_format 
should not be in quotes.


-Stut

--
http://stut.net/

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



RE: [PHP] mysql date question

2008-01-03 Thread Bastien Koert

no need for quotes
 
select date_format(contract.length_start, '%m-%d-%Y') as length_start from 
contract where user_id = 1;
 
bastien
 Date: Thu, 3 Jan 2008 08:30:55 -0600 From: [EMAIL PROTECTED] To: 
 php-general@lists.php.net Subject: [PHP] mysql date question  I have a 
 field in mysql as shown by describe contract;  | length_start | date | YES 
 | | NULL  | |  Which stores it in the mysql format of -MM-DD. However, 
 I need the  output of my select statement to show it in MM-DD- format. I 
 can  select it to see the date in the field:  select length_start from 
 contract where user_id = 1; +--+ | length_start | 
 +--+ | 2006-01-12 | +--+ 1 row in set (0.00 sec) 
  so then I do my date_format() select statement, but it returns a NULL  
 value. Why?  select date_format('contract.length_start', '%m-%d-%Y') as 
 length_start  from contract where user_id = 1; +--+ | 
 length_start | +--+ | NULL | +--+ 1 row in set, 1 
 warning (0.00 sec)  --  PHP General Mailing List (http://www.php.net/) To 
 unsubscribe, visit: http://www.php.net/unsub.php 
_
Discover new ways to stay in touch with Windows Live! Visit the City @ Live 
today!
http://getyourliveid.ca/?icid=LIVEIDENCA006

RE: [PHP] mysql date question

2008-01-03 Thread Jay Blanchard
[snip]
I have a field in mysql as shown by describe contract;

| length_start | date| YES  | | NULL
||

Which stores it in the mysql format of -MM-DD.  However, I need the 
output of my select statement to show it in MM-DD- format.  I can 
select it to see the date in the field:

select length_start from contract where user_id = 1;
+--+
| length_start |
+--+
| 2006-01-12   |
+--+
1 row in set (0.00 sec)

so then I do my date_format() select statement, but it returns a NULL 
value.  Why?

select date_format('contract.length_start', '%m-%d-%Y') as length_start 
from contract where user_id = 1;
+--+
| length_start |
+--+
| NULL |
+--+
1 row in set, 1 warning (0.00 sec)
[/snip]


Actually this is more a question for the MySQL list.

Start first by taking the ticks or quotes off of the column;

select date_format(contract.length_start, '%m-%d-%Y') as length_start 
from contract where user_id = 1;

You are essentially trying to turn that text string into a date, it will
not work.

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



Re: [PHP] mysql date question

2008-01-03 Thread Silvio Porcellana

Uhm, a shot in the dark - try:
select date_format(contract.length_start, '%m-%d-%Y') as length_start

HTH, cheers!
Silvio

Adam Williams wrote:

I have a field in mysql as shown by describe contract;

| length_start | date| YES  | | NULL
||


Which stores it in the mysql format of -MM-DD.  However, I need the 
output of my select statement to show it in MM-DD- format.  I can 
select it to see the date in the field:


select length_start from contract where user_id = 1;
+--+
| length_start |
+--+
| 2006-01-12   |
+--+
1 row in set (0.00 sec)

so then I do my date_format() select statement, but it returns a NULL 
value.  Why?


select date_format('contract.length_start', '%m-%d-%Y') as length_start 
from contract where user_id = 1;

+--+
| length_start |
+--+
| NULL |
+--+
1 row in set, 1 warning (0.00 sec)



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



Re: [PHP] mysql date question

2008-01-03 Thread Richard Lynch
On Thu, January 3, 2008 8:30 am, Adam Williams wrote:
 I have a field in mysql as shown by describe contract;

 | length_start | date| YES  | | NULL
 ||

 Which stores it in the mysql format of -MM-DD.  However, I need
 the
 output of my select statement to show it in MM-DD- format.  I can
 select it to see the date in the field:

 select length_start from contract where user_id = 1;
 +--+
 | length_start |
 +--+
 | 2006-01-12   |
 +--+
 1 row in set (0.00 sec)

 so then I do my date_format() select statement, but it returns a NULL
 value.  Why?

 select date_format('contract.length_start', '%m-%d-%Y') as
 length_start
 from contract where user_id = 1;
 +--+
 | length_start |
 +--+
 | NULL |
 +--+
 1 row in set, 1 warning (0.00 sec)

There is not PHP in this question.

But to save you subscribing/posting/unsubcribing to the MySQL list:

You put apostrophes on 'contract.length_start' which makes it a
literal DATE.

MySQL silently ignores such a stupid-looking date, and makes it NULL.

Take away the apostrophes on the FIELD NAME and all will be good.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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


RE: [PHP] A DATE Question

2003-10-08 Thread Jay Blanchard
[snip]
is there a function in PHP that will work out the amount of time(hours)
beween two different dates / times?
[/snip]

http://www.php.net/strtotime

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



Re: [PHP] A DATE Question

2003-10-08 Thread Eugene Lee
On Wed, Oct 08, 2003 at 03:08:44PM +0100, Shaun wrote:
: 
: is there a function in PHP that will work out the amount of time(hours)
: beween two different dates / times?

Just convert the two times into Unix timestamps, subtract one from the
other, and the difference is the amount of time in seconds.  Then it's
a simple matter of math to convert from seconds to hours (and minutes).

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



Re: [PHP] Simple date question

2003-07-30 Thread David Nicholson
Hello,

This is a reply to an e-mail that you wrote on Wed, 30 Jul 2003 at
19:18, lines prefixed by '' were originally written by you.

 If I have:
 $firstdate = 2003-06-28;
 then how can I get $firstdate plus 4 days?
 Thanks!

date(Y-d-m,mktime(0,0,0,substr($firstdate,5,2),substr($firstdate,8,2),substr($firstdate,0,4))
+ (60*60*24*4));

Should do the trick, you can probably use strtotime instead of all
the substr()'s but at a guess I would expect the above to be quicker
(not that I have benchmarked it).

HTH

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

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



Re: [PHP] Simple date question

2003-07-30 Thread Kevin Stone

David Nicholson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hello,

This is a reply to an e-mail that you wrote on Wed, 30 Jul 2003 at
19:18, lines prefixed by '' were originally written by you.

 If I have:
 $firstdate = 2003-06-28;
 then how can I get $firstdate plus 4 days?
 Thanks!

date(Y-d-m,mktime(0,0,0,substr($firstdate,5,2),substr($firstdate,8,2),subs
tr($firstdate,0,4))
+ (60*60*24*4));

Should do the trick, you can probably use strtotime instead of all
the substr()'s but at a guess I would expect the above to be quicker
(not that I have benchmarked it).

HTH

David.
--

David's reply was spot on but I thought I'd break it down for you in case
you didn't understand...

$firstdate = 2003-06-28;

// Parse the date
list($year, $month, $day) = explode(-, $firstdate);

// Get the timestamp for this date..
$ts = mktime(0,0,0,$month,$day,$year);

// Add four days to timestamp..
$ts += 345600;

// Get year, month, day for new date..
$newdate = date(Y-m-d, $ts);

The only thing that I'm doing differntly is the way in which I'm parsing the
date.  I'm using the list()=explode() method as opposed to substr() becuase
this method is not prone to fail when values are not zero filled.

Good luck,
Kevin



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



Re: [PHP] Simple date question

2003-07-30 Thread Jeff Harris
On Jul 30, 2003, Roy W claimed that:

|If I have:
|
|$firstdate = 2003-06-28;
|
|then how can I get $firstdate plus 4 days?
|
|Thanks!

It looks like that date may have come from a [mysql] database. If that's
the case, you should be able to add 4 days in your query, by using
DATE_ADD()
check http://www.mysql.com/doc/en/Date_and_time_functions.html

Jeff
-- Registered Linux user #304026.
lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import
Key fingerprint = 52FC 20BD 025A 8C13 5FC6  68C6 9CF9 46C2 B089 0FED
Responses to this message should conform to RFC 1855.



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



Re: [PHP] simple date question

2003-01-20 Thread Rick Emery
Why not just get the month with another call to date(m) as well?  Then call date(W) 
to get the
week, if that's required?
- Original Message -
From: adrian [EMAIL PROTECTED] [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, January 20, 2003 8:42 AM
Subject: [PHP] simple date question


this is pretty simple but my brain's not working

I get the numerical value of a week in the year thus

e.g  $today = date(W);

gives 4 .so this is the 4th week of the year.
I want to get the month based on this number.
e.g 4 should be january. 7 will be feb etc..

i'm not bothered about being too exact ,where some weeks are in 2 separate
months,
the earlier month should be displayed.and this is just for 2003.

thanks,
adrian



--
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] simple date question

2003-01-20 Thread Justin French
why not just call date('m') to get the month?

justin


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




Re: [PHP] Re: date question

2002-09-29 Thread Matt

 From: Jonas Geiregat [EMAIL PROTECTED]
 Sent: Sunday, September 29, 2002 10:56 AM
 Subject: [PHP] Re: date question


 and If I want to calculate from given date the next month
 like strtotime(next month) gives me the date of one month in advanced
 from NOW
 but I want to get the date one month in advanced from a given date not NOW

If you have mysql lying around, it has a bunch of date functions that can do
what you want:
http://www.mysql.com/doc/en/Date_and_time_functions.html



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




Re: [PHP] Newbie Date question

2002-07-14 Thread Jason Wong

On Monday 15 July 2002 00:01, RoyW wrote:
 If:

 $today = date(Y-m-d);

 Then how to I get:

 $yesterday = ?

Use strtotime() followed by date(). Details in manual.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I went to a Grateful Dead Concert and they played for SEVEN hours.  Great 
song.
-- Fred Reuss
*/


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




RE: [PHP] easy date question?

2002-05-29 Thread Ford, Mike [LSS]

 -Original Message-
 From: Ed Lazor [mailto:[EMAIL PROTECTED]]
 Sent: 29 May 2002 01:49
 To: [EMAIL PROTECTED]
 Subject: [PHP] easy date question?
 
 
 How can I find out the date of the 3rd Tuesday of any given month?
 
 Thanks,

To get a timestamp value:

$third_tues = strtotime('tue + 2 weeks', strtotime('1-may-2002'));

which you can then use date() to format however you want.

Of course, if you already have a timestamp for the first of the month you can use this 
in place of the second strtotime() call.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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




Re: [PHP] easy date question?

2002-05-28 Thread Rasmus Lerdorf

See the PEAR Date/Calc class.

On Tue, 28 May 2002, Ed Lazor wrote:

 How can I find out the date of the 3rd Tuesday of any given month?

 Thanks,

 -Ed


 --
 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] easy date question?

2002-05-28 Thread Martin Towell

1. set date = 1
2. get day of 1st of month
3. if day != tuesday, set date = 10-day_num  (assuming Sun = 0, Mon = 1,
etc)
4. add 14 to date
5. now you have your date

There's most likely a better way of doing it though

-Original Message-
From: Ed Lazor [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 10:49 AM
To: [EMAIL PROTECTED]
Subject: [PHP] easy date question?


How can I find out the date of the 3rd Tuesday of any given month?

Thanks,

-Ed


-- 
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] easy date question?

2002-05-28 Thread Ed Lazor

I came up with a solution that I'd like to share.  Could someone confirm 
whether it's the best approach?

Thanks,

-Ed

- source code 

# ex.: GetDay (Third, Saturday, 5, 2002);
function GetDay($Week, $Day, $Month, $Year)
{
 $MonthStartDay = date(w, mktime(0,0,0,$Month,1,$Year) ) + 1;

 switch ($Week)
 {
 case First : $Week = 0; break;
 case Second : $Week = 7; break;
 case Third : $Week = 14; break;
 case Fourth : $Week = 21; break;
 }

 switch ($Day)
 {
 case Sunday : $Day = 1; break;
 case Monday : $Day = 2; break;
 case Tuesday : $Day = 3; break;
 case Wednesday : $Day = 4; break;
 case Thursday : $Day = 5; break;
 case Friday : $Day = 6; break;
 case Saturday : $Day = 7; break;
 }

 $C = 0;

 if ($MonthStartDay  $Day)
 {
 $C = $Day - $MonthStartDay;
 }
 else if ($MonthStartDay  $Day)
 {
 $C = 7 - $MonthStartDay + $Day;
 }

 return ($C + 1 + $Week);
}








At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote:
See the PEAR Date/Calc class.

On Tue, 28 May 2002, Ed Lazor wrote:

  How can I find out the date of the 3rd Tuesday of any given month?
 
  Thanks,
 
  -Ed


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




RE: [PHP] easy date question?

2002-05-28 Thread Martin Towell

If you want to make it a few line shorter, change

 if ($MonthStartDay  $Day)
 {
 $C = $Day - $MonthStartDay;
 }
 else if ($MonthStartDay  $Day)
 {
 $C = 7 - $MonthStartDay + $Day;
 }

to

 $C = ($MonthStartDay  $Day ? 7 : 0) + $Day - $MonthStartDay;

or maybe

 $C = ($MonthStartDay  $Day ? 0 : 7) + $Day - $MonthStartDay;

I haven't tried either one, so it may break it...

If one, or both, work, then you could combine this line with the return
line

-Original Message-
From: Ed Lazor [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 2:44 PM
To: Rasmus Lerdorf
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] easy date question?


I came up with a solution that I'd like to share.  Could someone confirm 
whether it's the best approach?

Thanks,

-Ed

- source code 

# ex.: GetDay (Third, Saturday, 5, 2002);
function GetDay($Week, $Day, $Month, $Year)
{
 $MonthStartDay = date(w, mktime(0,0,0,$Month,1,$Year) ) + 1;

 switch ($Week)
 {
 case First : $Week = 0; break;
 case Second : $Week = 7; break;
 case Third : $Week = 14; break;
 case Fourth : $Week = 21; break;
 }

 switch ($Day)
 {
 case Sunday : $Day = 1; break;
 case Monday : $Day = 2; break;
 case Tuesday : $Day = 3; break;
 case Wednesday : $Day = 4; break;
 case Thursday : $Day = 5; break;
 case Friday : $Day = 6; break;
 case Saturday : $Day = 7; break;
 }

 $C = 0;

 if ($MonthStartDay  $Day)
 {
 $C = $Day - $MonthStartDay;
 }
 else if ($MonthStartDay  $Day)
 {
 $C = 7 - $MonthStartDay + $Day;
 }

 return ($C + 1 + $Week);
}








At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote:
See the PEAR Date/Calc class.

On Tue, 28 May 2002, Ed Lazor wrote:

  How can I find out the date of the 3rd Tuesday of any given month?
 
  Thanks,
 
  -Ed


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