dbTalk Databases Forums  

Date... Fixed Day, minus one month

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Date... Fixed Day, minus one month in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Oliver
 
Posts: n/a

Default Date... Fixed Day, minus one month - 07-23-2010 , 05:49 AM






Dear all

It might be a trivial issue for you.. but it keeps me busy and I'd be
glad for help.


Lets say, we now have "23.07.2010 13:45:21" as dd.mm.yyyy hh:mm:ss.
I like to get the following date 20.06.2010. This is "today minus one
month" and "always day 20".

What I have currently is:
TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'DD-MM-YYYY HH:MM:SS')

I've been traing with a lot of things but couldn't get it working...

How can I have a fixed day in DD?

Oliver

Reply With Quote
  #2  
Old   
Kay Kanekowski
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 07-23-2010 , 06:37 AM






On 23 Jul., 12:49, Oliver <olit... (AT) gmail (DOT) com> wrote:
Quote:
Lets say, we now have "23.07.2010 13:45:21" as dd.mm.yyyy hh:mm:ss.
I like to get the following date 20.06.2010. This is "today minus one
month" and "always day 20".
Hi Oliver,
try this:

select sysdate - d.offset_day day,
TO_CHAR(ADD_MONTHS(sysdate - d.offset_day, -1), 'DD-MM-
YYYY HH:MM:SS') day_1_month,
'20-' || TO_CHAR(ADD_MONTHS(sysdate - d.offset_day, -1), 'MM-
YYYY HH:MM:SS') only_20th
from dual,
(select level offset_day
from dual
connect by level <= 93) d;


DAY DAY_1_MONTH ONLY_20TH
-------- ------------------- -------------------
22.07.10 22-06-2010 01:06:14 20-06-2010 01:06:14
....
01.07.10 01-06-2010 01:06:14 20-06-2010 01:06:14
30.06.10 31-05-2010 01:05:14 20-05-2010 01:05:14
....
01.06.10 01-05-2010 01:05:14 20-05-2010 01:05:14
31.05.10 30-04-2010 01:04:14 20-04-2010 01:04:14


hth
Kay

Reply With Quote
  #3  
Old   
Carlos
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 07-23-2010 , 06:56 AM



On Jul 23, 12:49*pm, Oliver <olit... (AT) gmail (DOT) com> wrote:
Quote:
Dear all

It might be a trivial issue for you.. but it keeps me busy and I'd be
glad for help.

Lets say, we now have "23.07.2010 13:45:21" as dd.mm.yyyy hh:mm:ss.
I like to get the following date 20.06.2010. This is "today minus one
month" and "always day 20".

What I have currently is:
TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'DD-MM-YYYY HH:MM:SS')

I've been traing with a lot of things but couldn't get it working...

How can I have a fixed day in DD?

Oliver
CARLOS (AT) XE (DOT) localhost> select ADD_MONTHS(trunc(sysdate, 'MONTH'), -1 ) +
19 from dual;

ADD_MONTHS(TRUNC(SY
-------------------
2010/06/20 00:00:00

HTH.

Cheers.

Carlos.

Reply With Quote
  #4  
Old   
Oliver
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 07-23-2010 , 07:59 AM



On 23 Jul., 13:37, Kay Kanekowski <kay.kanekow... (AT) web (DOT) de> wrote:
....
Quote:
* * * *'20-' || TO_CHAR(ADD_MONTHS(sysdate - d.offset_day, -1), 'MM-
YYYY HH:MM:SS') only_20th
....

Does the Job. Thank you! VERY MUCH!

Oliver

Reply With Quote
  #5  
Old   
Oliver
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 07-23-2010 , 08:06 AM



On 23 Jul., 13:56, Carlos <miotromailcar... (AT) netscape (DOT) net> wrote:
Quote:
On Jul 23, 12:49*pm, Oliver <olit... (AT) gmail (DOT) com> wrote:





Dear all

It might be a trivial issue for you.. but it keeps me busy and I'd be
glad for help.

Lets say, we now have "23.07.2010 13:45:21" as dd.mm.yyyy hh:mm:ss.
I like to get the following date 20.06.2010. This is "today minus one
month" and "always day 20".

What I have currently is:
TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'DD-MM-YYYY HH:MM:SS')

I've been traing with a lot of things but couldn't get it working...

How can I have a fixed day in DD?

Oliver

CAR... (AT) XE (DOT) localhost> select ADD_MONTHS(trunc(sysdate, 'MONTH'), -1 ) +
19 from dual;

ADD_MONTHS(TRUNC(SY
-------------------
2010/06/20 00:00:00

HTH.

Cheers.

Carlos.- Zitierten Text ausblenden -

Hi Carlos

Thank you. I've decided to use Kays solution.
It feels more "right" as it does what I've asked.

Altough your solution it does a count in a mathematical term and not
like a string concatination.
....so, it is more an conceptual/ theoretical issue.

What I'd prefere realy - from conceptual point of view - would be a
syntax like '20-mm-yyyy' or 'dd=20.mm.yyyy'. According this logic we
could have 'Last_Day(dd)-mm=08-yyyy=2010' ...but that sure is not
working.
Maybe I could ask oracle to do me a favor (I think they owe me
one...) ;-)

Oliver

Reply With Quote
  #6  
Old   
Shakespeare
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 07-23-2010 , 11:10 AM



Op 23-7-2010 15:06, Oliver schreef:
Quote:
On 23 Jul., 13:56, Carlos<miotromailcar... (AT) netscape (DOT) net> wrote:
On Jul 23, 12:49 pm, Oliver<olit... (AT) gmail (DOT) com> wrote:





Dear all

It might be a trivial issue for you.. but it keeps me busy and I'd be
glad for help.

Lets say, we now have "23.07.2010 13:45:21" as dd.mm.yyyy hh:mm:ss.
I like to get the following date 20.06.2010. This is "today minus one
month" and "always day 20".

What I have currently is:
TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'DD-MM-YYYY HH:MM:SS')

I've been traing with a lot of things but couldn't get it working...

How can I have a fixed day in DD?

Oliver

CAR... (AT) XE (DOT) localhost> select ADD_MONTHS(trunc(sysdate, 'MONTH'), -1 ) +
19 from dual;

ADD_MONTHS(TRUNC(SY
-------------------
2010/06/20 00:00:00

HTH.

Cheers.

Carlos.- Zitierten Text ausblenden -


Hi Carlos

Thank you. I've decided to use Kays solution.
It feels more "right" as it does what I've asked.

Altough your solution it does a count in a mathematical term and not
like a string concatination.
...so, it is more an conceptual/ theoretical issue.

What I'd prefere realy - from conceptual point of view - would be a
syntax like '20-mm-yyyy' or 'dd=20.mm.yyyy'. According this logic we
could have 'Last_Day(dd)-mm=08-yyyy=2010' ...but that sure is not
working.
Maybe I could ask oracle to do me a favor (I think they owe me
one...) ;-)

Oliver

How about:

SQL> select trunc(sysdate - interval '1' month,'MM') + interval '19' day
from dual;
I like the interval syntax because it documents exactly what and how
many you are adding to a date.

Shakespeare

Reply With Quote
  #7  
Old   
Oliver
 
Posts: n/a

Default Re: Date... Fixed Day, minus one month - 08-06-2010 , 03:31 AM



On 23 Jul., 18:10, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
....
Quote:
How about:

SQL> select trunc(sysdate - interval '1' month,'MM') + interval '19' day
from dual;
I like the interval syntax because it documents exactly what and how
many you are adding to a date.

Shakespeare
Agree and changed my code.
Thank you!

Oliver

Reply With Quote
Reply




Thread Tools
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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.