Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > Postgres SQL error. Plz help me.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-07, 02:20
eranda eranda is offline
Registered User
 
Join Date: Jan 2007
Posts: 11
Postgres SQL error. Plz help me.

I have write this sql with php.....

PHP Code:
$endDate "09/21/2007 10:30";
$startDate "09/21/2007 08:30";
    
$query "select mtas_jbnumber,to_char(mtas_origitargtodate,'MM/DD/YYYY'),to_char(mtas_origitargfrmdate,'MM/DD/YYYY') from im.mta where to_char(mtas_origitargfrmdate,'MM/DD/YYYY HH24:MI') < '$endDate'
and  to_char(mtas_origitargtodate,'MM/DD/YYYY HH24:MI') > '$startDate' and mtas_assignee = '$txtMCode' and mtas_perform <> 'D'"


But in the table "mta" exists only dates in 2006.
mtas_origitargtodate and mtas_origitargfrmdate are timestamps

But when i run the sql, it retrieves dates in 2006. how can it hapens? Even i change above start and end date 's year to 2008, it retrieves 2006 dates. But month and the date works fine. It's like that year is not considered. Plz can anyone help me?
Thnx...
Reply With Quote
  #2 (permalink)  
Old 09-24-07, 08:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
in your TO_CHAR expressions, use YYYY-MM-DD format
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 09-24-07, 08:34
eranda eranda is offline
Registered User
 
Join Date: Jan 2007
Posts: 11
Quote:
Originally Posted by r937
in your TO_CHAR expressions, use YYYY-MM-DD format

No that cant do... because i have used "MM/DD/YYYY" format everywhere .....

This is a strange thing.... I cant understand wht is happening there...
Reply With Quote
  #4 (permalink)  
Old 09-24-07, 08:35
eranda eranda is offline
Registered User
 
Join Date: Jan 2007
Posts: 11
Im leaving.. now.....
C u tomorrow morning.. bye...
Reply With Quote
  #5 (permalink)  
Old 09-24-07, 13:50
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
to_char is an Oracle function, not a Postgres function.

And please: post SQL code, not PHP code.
With that I mean a statement that can be run with e.g. SQL*Plus (or psql, if you are indeed using Postgres).
First get your statement working with pure SQL then put it into a PHP script.

I know nothing of PHP, so this answer might be wrong, but I would assume you need something like:

Code:
mtas_origitargtodate > to_date('$startDate', ,'MM/DD/YYYY HH24:MI')

assuming that mtas_origitargtodate is of type DATE
Reply With Quote
  #6 (permalink)  
Old 10-01-07, 05:02
eranda eranda is offline
Registered User
 
Join Date: Jan 2007
Posts: 11
Quote:
Originally Posted by shammat
to_char is an Oracle function, not a Postgres function.

And please: post SQL code, not PHP code.
With that I mean a statement that can be run with e.g. SQL*Plus (or psql, if you are indeed using Postgres).
First get your statement working with pure SQL then put it into a PHP script.

I know nothing of PHP, so this answer might be wrong, but I would assume you need something like:

Code:
mtas_origitargtodate > to_date('$startDate', ,'MM/DD/YYYY HH24:MI')

assuming that mtas_origitargtodate is of type DATE

Hey.....
thnx for helping me....
Actually type of mtas_origitargtodate is Timestamp.
So i changed my sql to
Code:
mtas_origitargtodate > to_timestamp('$startDate','MM/DD/YYYY HH24:MI')

Then my problem solved.......
Thnx everyone who tried to help me.
Reply With Quote
  #7 (permalink)  
Old 10-02-07, 12:42
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,359
Quote:
Originally Posted by shammat
to_char is an Oracle function, not a Postgres function.
While the CAST function is often used (Ref 4.2.8), to_char, to_number, to_date, and to_timestamp are all valid PostgreSQL function ...
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin : 10-02-07 at 12:48.
Reply With Quote
  #8 (permalink)  
Old 10-02-07, 12:57
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
Quote:
Originally Posted by loquin
While the CAST function is often used (Ref 4.2.8), to_char, to_number, to_date, and to_timestamp are all valid PostgreSQL function ...
Ah! Didn't know that
Thanks for the hint
Reply With Quote
  #9 (permalink)  
Old 10-02-07, 15:39
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,359
I've never tried looking it up, but I wonder of they're all just wrappers for the CAST function to coddle the Oracle users?
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On