473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Urgent : Help to convert string to date

Hi
My requirement is to compare a date in string format with the Sysdate. The problem is the date string does not contain a zero before the single digit date and month.

Here is my query

select * from table_name where to_date(%date%, 'MM/DD/YYYY) > (SYSDATE - 7);

this gives an error saying the month is not valid when the month in %date% is single digit.
Please help

Thanks
Oct 17 '07 #1
3 2765
amitpatel66
2,367 Expert 2GB
Hi
My requirement is to compare a date in string format with the Sysdate. The problem is the date string does not contain a zero before the single digit date and month.

Here is my query

select * from table_name where to_date(%date%, 'MM/DD/YYYY) > (SYSDATE - 7);

this gives an error saying the month is not valid when the month in %date% is single digit.
Please help

Thanks
This error is because the NLS_DATE_FORMAT is something different for your session from the format that you are using.

Run the below query in your session before running the above select statement:

Expand|Select|Wrap|Line Numbers
  1. ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/RRRR';
  2.  
Oct 18 '07 #2
Hi,

This may not look pretty but, if you run a query,

select ltrim(to_char(sysdate - 195,'DD'),'0') || '/' || ltrim(to_char(sysdate - 195,'MM'),'0') || '/' || to_char(sysdate - 195,'YYYY') from dual

you will see the system date in dd/mm/yyyy format without zeros.
All I have done is put a ltrim on to_char and trimmed the day and month saperately and then appended them.

You can use such string and directly equate with your date.

Regards
Oct 19 '07 #3
select * from emp
where to_date(to_char(sysdate,'mm/dd/yyyy'),'mm/dd/yyyy') > to_date(to_char(SYSDATE-7,'mm/dd/yyyy'),'mm/dd/yyyy');
Try this..................
Oct 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dinçer | last post by:
I need to compare dates. But this way: I get a date from database. I need to understand if this date is newer then "6 months" or not. What I need is get the current date, calculate the date 6...
0
by: john | last post by:
Hi,All MS Tech Gurus: I need your help!!! It is the second time I post this message, I need get some feedback ASAP, Please Help!! Thanks a lot in advance. John I have a csharp method, using...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
5
by: Vishal | last post by:
Hey, I have differnt kind of dates. They can be in this format: Thur, 23 Sept 2004 14:24:15 GMT Thur, 23 Sept 2004 14:24:15 PST Thur, 23 Sept 2004 14:24:15 CST and so on....
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: meenasamy | last post by:
Hi all, i need to create a function that takes three parameters( Original currency, needed currency, amount) i need to convert from the original currency to the needed currency the amount and...
3
by: ricolee99 | last post by:
Hi everyone, I have a problem that i have been trying to solve for awhile. I'm given a code where the purpose is to create a general dataset mapper. Given any dataset, i have a class,...
32
by: jamieexley | last post by:
what are the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004????
2
by: santoshpayal | last post by:
Hi, I have a text file that contains a date column. The text file will be imported to database in SQL 2000 server. After to be importing, I want to convert the date column to date type. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.