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



[PHP] Re: PHP MySQL DATE comparison

2004-06-16 Thread Torsten Roehr
Ryan Schefke [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hello,



 I'm pulling a date in the datetime format via a MySQL query.  Using PHP
I
 would like to check if that date is prior to today's date.  Can someone
 please help with this quick question.

You could convert it to a timestamp via strtotime() and check it against
time():

$date = strtotime($dateFromDb);

if ($date  time()) {
echo 'Date is in the past.';
}

Regards, Torsten Roehr

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



RE: [PHP] MySQL Date

2003-03-19 Thread Barajas, Arturo
Shaun,

It should be: date(Y-m-d). MySQL stores the dates as -mm-dd, and that function 
returns the current date on the format you need.

Check the date() function on the php manual.
--
Un gran saludo/Big regards...
   Arturo Barajas, IT/Systems PPG MX (SJDR)
   (427) 271-9918, x448

 -Original Message-
 From: shaun [mailto:[EMAIL PROTECTED]
 Sent: Miercoles, 19 de Marzo de 2003 07:19 a.m.
 To: [EMAIL PROTECTED]
 Subject: [PHP] MySQL Date
 
 
 Hi,
 
 I have a date stored in a table in my MySQL Database using a 
 DATE type for
 the column.
 
 How can i compare the date in the table to today
 
 e.g.
 
 $today = mysql_result($result, $i, Booking_Date);
 
 if($today = *HELP*){
 echo you are booked today;
 }else{
 echo you are free today;
 }
 
 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



RE: [PHP] MySQL Date

2003-03-19 Thread John W. Holmes
 I have a date stored in a table in my MySQL Database using a DATE type
for
 the column.
 
 How can i compare the date in the table to today

... WHERE your_date = CURDATE() ...

 e.g.
 
 $today = mysql_result($result, $i, Booking_Date);
 
 if($today = *HELP*){

or...

if($today == date('Y-m-d'))

(notice the second equals sign!)

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



RE: [PHP] Mysql date format

2002-11-07 Thread John W. Holmes
 I'm using php with MySql.
 I'm migrating an php-oracle application to php-mysql. I need to know
if
 exists any function in mysql similar to the to_char or to_date
 functions
 of oracle; or format function of access?. These functions make a
date
 format or numeric format.
 
 ex:  to_char(sysdate,'dd/mm/ hh:mi:ss') return a string with the
 actual
 datetime in the specified format.

MySQL has the DATE_FORMAT() function to do this.

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

---John Holmes...



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




Re: [PHP] mySQL date converting

2001-08-07 Thread Bjorn Van Simaeys

Hi,


You could write a PHP script to get all the current
values (I presume that you've put varchar as
datatype), parse them with string functions and
convert it in the way you'd like them to be. All this
is not so difficult to make.

I prefer to store my date/times in the UNIX timestamp
form. I use an int(10) field in mySQL database
(int(10) means an integer with 10 digits, this way I
can store more than 331 years!). This is easy to sort
and to calculate with too. In your development you can
use this timestamp and format it in any way you want
it using the date() function.

You'll find all references in the php.net manual.


Greetz,
Bjorn Van Simaeys
www.bvsenterprises.com


--- Christopher CM Allen [EMAIL PROTECTED] wrote:
 Greetings:
 
 I have a field entry in a MYQSL table that stores
 the date as:
 August 02, 2001 :(
 
 Is there anyway to convert this to 08-02-2001
 outside of the table via php?
 
 Better yet is there ayway I can go back into my
 table and change these dates
 into a better format for computation?
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 To contact the list administrators, e-mail:
 [EMAIL PROTECTED]
 


__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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