Select first day and last day of previous month sqlplus unixtimestamp
up vote
0
down vote
favorite
I want to extract the whole last month data using sqlplus
, based on a column that is unixtimestamp
, and I am not able to find the correct query. Using
unixtimestamp_column >= to_number((add_months(sysdate,-1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000";
it outputs from the day when the script is run due do the sysdate
used. I want to be able to extract from the first day 00:00:00 of the previous month until the last day 23:59:59 of the previous month. Also, the user should not pass any kind of parameter or argument.
solaris sqlplus
|
show 1 more comment
up vote
0
down vote
favorite
I want to extract the whole last month data using sqlplus
, based on a column that is unixtimestamp
, and I am not able to find the correct query. Using
unixtimestamp_column >= to_number((add_months(sysdate,-1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000";
it outputs from the day when the script is run due do the sysdate
used. I want to be able to extract from the first day 00:00:00 of the previous month until the last day 23:59:59 of the previous month. Also, the user should not pass any kind of parameter or argument.
solaris sqlplus
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to useTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead ofadd_months(sysdate,-1))
, andTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).
– fra-san
Nov 27 at 10:07
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
1
I think what you need is something likeunixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
andunixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
1
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
3
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to extract the whole last month data using sqlplus
, based on a column that is unixtimestamp
, and I am not able to find the correct query. Using
unixtimestamp_column >= to_number((add_months(sysdate,-1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000";
it outputs from the day when the script is run due do the sysdate
used. I want to be able to extract from the first day 00:00:00 of the previous month until the last day 23:59:59 of the previous month. Also, the user should not pass any kind of parameter or argument.
solaris sqlplus
I want to extract the whole last month data using sqlplus
, based on a column that is unixtimestamp
, and I am not able to find the correct query. Using
unixtimestamp_column >= to_number((add_months(sysdate,-1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000";
it outputs from the day when the script is run due do the sysdate
used. I want to be able to extract from the first day 00:00:00 of the previous month until the last day 23:59:59 of the previous month. Also, the user should not pass any kind of parameter or argument.
solaris sqlplus
solaris sqlplus
edited Nov 27 at 10:41
fra-san
1,106214
1,106214
asked Nov 27 at 8:58
bboy
274
274
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to useTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead ofadd_months(sysdate,-1))
, andTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).
– fra-san
Nov 27 at 10:07
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
1
I think what you need is something likeunixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
andunixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
1
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
3
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54
|
show 1 more comment
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to useTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead ofadd_months(sysdate,-1))
, andTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).
– fra-san
Nov 27 at 10:07
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
1
I think what you need is something likeunixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
andunixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
1
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
3
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to use
TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead of add_months(sysdate,-1))
, and TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).– fra-san
Nov 27 at 10:07
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to use
TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead of add_months(sysdate,-1))
, and TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).– fra-san
Nov 27 at 10:07
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
1
1
I think what you need is something like
unixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
and unixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
I think what you need is something like
unixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
and unixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
1
1
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
3
3
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484400%2fselect-first-day-and-last-day-of-previous-month-sqlplus-unixtimestamp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to U&L! It looks like your question is specific to Oracle Database/tools, so it's probably off-topic here. You might want to ask for it being migrated, possibly to StackOverflow. As for your question, you probably need to use
TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1
as the base date for the starting point of your time interval (instead ofadd_months(sysdate,-1))
, andTRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1)
as it's end point. Such an interval should be closed to the left (>=
), open to the right (<
).– fra-san
Nov 27 at 10:07
I used : unixtimestamp_column >= TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60) * 1000"; and got identifier is too long .
– bboy
Nov 27 at 10:14
1
I think what you need is something like
unixtimestamp_column >= (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-2))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
andunixtimestamp_column < (TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1) - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 * 1000
– fra-san
Nov 27 at 14:04
1
Note that Unix timestamps are in UTC, while Oracle date functions output local times. This may be relevant to your application.
– fra-san
Nov 27 at 14:14
3
I'm voting to close this question as off-topic because it's about SQL
– roaima
Nov 28 at 8:54