How to subtract Time from Sysdate
Hello,
I want to subtract time from sysdate and get the sysdate with time.
Example : = (Sysdate with time)03-mar-2002 16:40:55 - 8 (hours). The result should be like :03-mar-2002 08:40:55
How to write a query for this?.
Please let me know as soon as possible.
Thanks,
Ravi.
Hi Ravi...
SYSDATE includes time, TRUNC(SYSDATE) does not include time.
If you subtract these two, you'll get a positive number of 1.00 or less which is the fraction of a day. For instance high noon would have a fraction of 0.50000. 12:01 p.m. would be 0.50000 + (1/(24*60)), or 0.50069444....
If you want to set the clock back, by calculating a "date" that is 8 hours less than the SYSDATE, then SYSDATE - (8/24) will do that. This will work even if SYSDATE was something like 2 a.m., because it will then set it to 6 p.m. of the day before the day in SYSDATE.
If you want to set a "date" to a specific time on the day of SYSDATE, then calculate the fraction for that time and add it to the TRUNC(SYSDATE). High noon would be TRUNC(SYSDATE) + 0.5.
SELECT TO_CHAR(TRUNC(SYSDATE)+0.5,'DD-MON-YY HH:MI:SS am') AS NOON FROM DUAL;Hope this helps...
Larry Johnson
Similar Messages
-
How to subtract time from dateTime in xquery?
How to subtract time from dateTime in xquery??
In ALDSP i tried to use the function xf:add-days but it is showing an error saying invalid function name. I think this namespace is not valid for ALDSP. Is there is any way to add this function in ALDSP???xquery functions and operators documentation is here :
http://www.w3.org/TR/xpath-functions/
It sounds like you want to ..
op:subtract-dayTimeDuration-from-dateTime
this is not an xquery function that you can call, it is an xquery operation defined by the specification
I believe you can simply use the '-' operator to use that operation.
<newDateTime>
{ $myDateTime - $myTime }
</newDateTime> -
Dear Sir,
I want to subtract Time from time, Please help me
SELECT A.EMP_CODE,
TO_DATE(A.INTIME,'DD/MM/RR')IN_DATE
,MIN(TO_CHAR(A.INTIME,'HH24:MI')) IN_TIME
,MAX(TO_CHAR(A.OUTTIME,'HH24:MI')) OUT_TIME
,TRUNC(SUM(A.TDAYS)*24)||':'||TRUNC((SUM(A.TDAYS)*24-TRUNC(SUM(A.TDAYS)*24))*60) TOTAL_TIME
FROM HCM.EINOUT A, HCM.PERSONNEL B
WHERE A.EMP_CODE = B.EMP_CODE AND
TO_DATE(A.INTIME,'DD/MM/RR')BETWEEN
TO_DATE('01/08/12','DD/MM/RR') AND TO_DATE('15/08/12','DD/MM/RR')
AND B.DEPT_CODE = 16 and a.emp_Code = '09833'
GROUP BY A.EMP_CODE, TO_DATE(A.INTIME,'DD/MM/RR')--, a.tdays
ORDER BY 1, 2 ASC;
I want to subtract 20:00 from (out_time) column from every record
If I subtract it from first record then result in over_time column will be 2:46
(out_time - 20:00)
--------------Out put........................
code date in_time out_time total_time over_time
09833 02-AUG-12 09:18 22:46 13:28
09833 03-AUG-12 09:16 21:50 12:34
09833 04-AUG-12 09:28 21:41 12:13
thanksthis will help
--And if difference can be > 24 hours:
WITH t AS
(SELECT TO_DATE ('26-aug-2011 10:10:10',
'dd-mon-yyyy hh24:mi:ss'
) start_date_time,
TO_DATE ('26-aug-2011 10:12:10',
'dd-mon-yyyy hh24:mi:ss'
) end_date_time
FROM DUAL)
SELECT TRUNC (end_date_time - start_date_time)
|| ' days '
|| TO_CHAR (TRUNC (SYSDATE) + (end_date_time - start_date_time),
'hh24:mi:ss'
) time_diff
FROM t
--Or interval based solution for < 24 hour diff:
WITH t AS
(SELECT TO_DATE ('26-aug-2011 10:10:10',
'dd-mon-yyyy hh24:mi:ss'
) start_date_time,
TO_DATE ('26-aug-2011 10:12:10',
'dd-mon-yyyy hh24:mi:ss'
) end_date_time
FROM DUAL)
SELECT REGEXP_SUBSTR (NUMTODSINTERVAL (end_date_time - start_date_time, 'day'),
'\d\d:\d\d:\d\d'
) time_diff
FROM t
--interval based solution for >= 24 hour diff:
WITH t AS
(SELECT TO_DATE ('26-aug-2011 10:10:10',
'dd-mon-yyyy hh24:mi:ss'
) start_date_time,
TO_DATE ('26-aug-2011 10:12:10',
'dd-mon-yyyy hh24:mi:ss'
) end_date_time
FROM DUAL)
SELECT REGEXP_REPLACE (NUMTODSINTERVAL (end_date_time - start_date_time,
'day'),
'^.0*(\d+) (.{8}).+$',
'\1 days \2'
) time_diff
FROM t
--another method
SELECT TO_CHAR (TRUNC (nb_sec / 3600), '00')
|| ':'
|| TO_CHAR (nb_min - TRUNC (nb_sec / 3600) * 60, '00')
|| ':'
|| TO_CHAR (MOD (nb_sec, 60), '00')
FROM (SELECT (end_date_time - start_date_time) * 24 * 3600 nb_sec,
(end_date_time - start_date_time) * 24 * 60 nb_min
FROM ps_tb_ln_pdc_status_log)
--another method
SELECT SYSDATE + 3.45 / 24 AS "End Date", SYSDATE AS "Start Date",
CAST (SYSDATE + 3.45 / 24 AS TIMESTAMP) - SYSDATE AS "Duration"
FROM DUAL;Regards,
friend. -
How to Get Millisec from Sysdate
Hello all
How to get millisec from sysdate.
Pls let me know da query ..You can't get milliseconds from SYSDATE. In 9i and upwards you can get them from a timestamp, whether it be from the built-in functions SYSTIMESTAMP and LOCALTIMESTAMP or a timestamp column/variable of your own.
Unfortunately, Oracle only supplies the means to extract seconds, but fortunately, this includes the millilseconds, which are easy enough to get to as the following demonstrates:-
SQL> select extract(second from localtimestamp) from dual;
EXTRACT(SECONDFROMLOCALTIMESTAMP)
42.765535
SQL> select mod(extract(second from systimestamp),1) from dual;
MOD(EXTRACT(SECONDFROMSYSTIMESTAMP),1)
.181223Regards
Adrian -
SUBTRACT TIME FROM DATE & TIME
Hi.
I need FM which will SUBTRACT TIME from DATE & TIME.
Example:
Date = 05.05.2007
Time = 05:00:00
Time_subtract = 48:00:00
Return of FM:
Date = 03.05.2007
Time = 05:00:00
Do you know any FM?
Thanks!Hi, Check these function mod's
SD_DATETIME_DIFFERENCE
HRCM_TIME_PERIOD_CALCULATE
HR_ECM_GET_PERIOD_BETW_DATES
After you execute them in SE37 give the required input and you will get a correct output.
<b>REWARD IF USEFUL</b>
thanks n regards
Dinesh -
Formula for subtracting time from a datetime field
I have a field that is formatted as a datetime field. I just need to know how to subtract 3.5 hours from this time. How do I write a formula in crystal reports kindly help me.
Thanks in advance
Ramakrishna ReddyThis should do the trick...
DateAdd("n", -210, {TableName.DateField})
HTH,
Jason -
I have a Column that is defined as "DATE".it also Contains Time.........
I want to Get the Time only....so when i am using this
to_date(var_date,'hh12:mi:ss PM'),it is giving me date also and when i am using this
to_char(var_date,'hh12:mi:ss PM') then it is giving me all values similar to one of the top values in Column....
Then i Used EXTRACT function as
Select EXTRACT(HOUR FROM VAR_DATE).......
THEN IT THRWOING ERROR.......INVALID EXTRACT FIELD FOR EXTRACT SOURCE........
pLZ HELP HOW TO GET TIME...................................ONLY WITH AM AND PM......
Thanks in AdvanceHi,
to_char function should give the result as expected.
SQL> select to_char(sysdate, 'hh12:mi:ss PM') from dual ;
TO_CHAR(SYS
11:39:16 AM
SQL> select to_char(sysdate, 'hh12:mi:ss AM') from dual ;
TO_CHAR(SYS
11:39:32 AM
SQL> select to_char(sysdate,'hh:mi:ss') from dual ;
TO_CHAR(
11:40:04
SQL> select to_char(sysdate,'hh:mi:ss am') from dual ;
TO_CHAR(SYS
11:40:18 am
SQL> select to_char(sysdate,'hh:mi:ss pm') from dual ;
TO_CHAR(SYS
11:40:31 am
Thanks,
Siva -
Subtracting Minutes from SYSDATE
Hi there,
I am trying to create SQL that selects/inserts data that is equal to the sysdate minus 15 minutes.
I have tried to do a statement as follows:
SYSDATE - 1
Although this takes off a day.
Does anybody know how to subtract a date by minutes?
Cheers,
CJAnupama was showing you how to look at the results of your query to prove that the minutes were being subtracted. Inside another qurey, you'll wand something like
(<date_variable> - (<num_minutes>/ 24/ 60))
In other words
select *
from someTabe
where data_column > (sysdate - (10/ 24/ 60))
Would give you all records in the last 10 minutes.
Justin -
How to get Time from Different Work Station on the Network
Hi,
How do I get time from different work station on the network using its ip:port etc.
Lets say, my main server-side Java application is running on a work station 123.12.123.1:1527,
the client-side applications are accessing it using above IP.
what I wanna do is, use the time of 123.12.123.1 machine throughout the application, not client local time.
Appreciated..Ok, this network service on IP:Port is working for me, I hope this is the best way of doing it.
In server application, I have this
package RenameItToYourOwnPackage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
public class ServerSocketExample implements Runnable {
private ServerSocket server;
private int port = 7777;
Socket socket;
public void run() {
try {
System.out.println("Waiting for client message");
server = new ServerSocket(port);
while (true) {
socket = server.accept();
// Read a message sent by client application
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
String clientMessage = (String) ois.readObject();
System.out.println("Message sent by client: " + clientMessage);
// send current datetime to client
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));
ois.close();
oos.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}In the client application I have
package RenameItToYourOwnPackage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class ClientSocketExample {
static String dateTimeString;
public ClientSocketExample() {
public static String getServerDateString() {
try {
// Create a connection to the server socket on the server application
InetAddress host = InetAddress.getByName("127.0.0.1");
Socket socket = new Socket(host.getHostName(), 7777);
// Send a message to the server application
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject("Send me today's timestamp as string");
// Read the response by server application
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
dateTimeString = (String) ois.readObject();
//System.out.println("Message sent by server: " + message);
ois.close();
oos.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
return dateTimeString;
}And I run the service on the server-side with
new Thread(new ServerSocketExample()).start();On the client-side I receive the date with
System.out.println("DateTime on Server : " + ClientSocketExample.getServerDateString());Edited by: nkamir on Sep 13, 2010 2:53 PM -
Hi,
how to subtract 18 days from day : 04-10-2004
rgds,
KarnaSQL> select to_date('04-10-2004','dd-mm-yyyy')-18 from dual
SQL> /
TO_DATE('0
16/09/2004
SQL> -
How 2 prevent time from changing on leopard and vista?
if i maintain successive boots into the same OS on my macbook, the time is shown correctly, whereas on booting into another OS changes the time. how to prevent this from happening?
NeeravFrom what my brother says says about his set-up (he boots into 64 bit Vista periodically), apparently you can't. My understanding is that the two systems do a different version of time at boot, Vista uses a GMT setting in bios, and I think Mac use a local time in EFI. Anyway, the result is several hours difference between the two. I don't use Boot Camp, but I would think if you are on a network with Internet access, you should be able to have the clock reset automatically using System Prefs->Date and Time, and check the box at the top to automatically set the time from the Apple time server.
Francine
Francine
Schwieder -
How to use time from external source as signature time?
Hi,
I have a PubSec based acrobat X plugin for signature creation and verification. So far i knew that acrobat was using my local system time to get signing time and saved that time in the signature dictionary. Now i have to get the signing time from an NTP server, which is different from my local system time, and I want to put this time in the signingTime (M) of the Signature dictioniary. But so far i am unable to modify the (M) dictionary value.
Can you please guide me to achieve this goal?
thanksthanks for your prompt reply.
actually, using timestamps is not an option. Machine time can be changed and my requirement is to use NTP time during signing and set this time as signing time in the signature dictionary. I have tried adding the time in M dictionary in SigGetSigProperties() and SigGetSigValue() callbacks, but it has no effect.
My question is, is it possible to use time other, than machine time, as signing time in a signature (in signature dictionary) ?
If yes, then can i achieve this, a hint or a point in the right direction can suffice.
if no, then is this limitation part of the new plugin framework? because as far as i remember, it was allowed in digsig plugins.
Finally, can i achieve my goal in an unorthodox way?
thanks -
Extract time from sysdate or some other?
Dear all,
I want to extract the Hour as a number from sysdate. Plz guide me.
Ex: SELECT EXTRACT (YEAR FROM SYSDATE) FROM DUAL;
I want like SELECT EXTRACT (Hour FROM SYSDATE) FROM DUAL;
Thanks in Advance..you can use to_char function
select to_char(sysdate, 'hh24') from dualor use a timestamp with extract function
select systimestamp, extract(HOUR from systimestamp) from dual -
How to prevent timer from repeats
hello there i've made a countdown timer
and i want it when it finishes counting till 0 not repeating from the beginning but do some action
i uesd the method
timer.setRepeats(false);but it stops the timer from counting
i'm using javax.swing.timer;
and here is the code:
import java.math.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Timer1 extends JFrame {
JComboBox combo = new JComboBox();
JButton start = new JButton("Start");
JButton stop = new JButton("Stop");
JButton clear = new JButton("Clear");
JTextField time = new JTextField("");
javax.swing.Timer timer;
SimpleDateFormat timef = new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
long startT,stopT;
Date date=new Date();
public Timer1() {
super("Timer");
timef.setTimeZone(TimeZone.getTimeZone("GMT"));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
dispose();
System.exit(0);
setBounds(10,10,400,200);
getContentPane().setLayout(null);
start.setBounds(10,30,100,24);
start.setBackground(Color.green);
stop.setBounds(10,60,100,24);
stop.setBackground(Color.red);
combo.setBounds(10,90,100,25);
combo.setBackground(Color.blue);
clear.setBounds(150,60,100,24);
clear.setBackground(Color.green);
combo.addItem("1 Hour");
combo.addItem("2 Hours");
combo.addItem("3 Hours ");
combo.addItem("4 Hours");
combo.addItem("5 Hours");
combo.addItem("6 Hours");
combo.addItem("7 Hours");
combo.setSelectedIndex(0);
start.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
try {
startT=(combo.getSelectedIndex()+1)*60*60*1000; // change if combo box values changed
catch (Throwable fe) {
startT=0;
startT+=System.currentTimeMillis();
timer.start();
stop.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
timer.stop();
clear.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
time.setText("");
time.setBounds(150,30,100,24);
time.setOpaque(true);
time.setBackground(Color.pink);
getContentPane().add(stop);
getContentPane().add(start);
getContentPane().add(time);
getContentPane().add(combo);
getContentPane().add(clear);
timer = new javax.swing.Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
stopT = System.currentTimeMillis();
time.setText(timef.format(new Date(startT-stopT)));
setVisible(true);
public static void main (String[] args) {
UIManager.put("Label.font" ,new Font("Times New Roman",0,23));
UIManager.put("Button.font",new Font("Arial",1,21));
new Timer1();
}simply the user chooses a time from the combobox say
1 hour
and then hits the start button so the timer begins to
countdown.
my problem here is i want when the countdown timer
reaches 0 hour 0 minute 0 second the frame exit (or
any action)not repeating the default time .
got it?Ah, yes, now I understand. So when the user chooses an interval, 1 hour in this case, you calculate the number of seconds that make up that interval. (Doesn't have to be seconds, depends on the granularity of the choices) Then you count down that many seconds like I described before. Each time the timer ticks, decrement the counter, and also convert the number of second left back into hours, minues, seconds and display that.
So the counter becomes the data model that everything's based on, and you format it for display each tick.
startTimer() {
int interval = // get the interval selected from the combobox
int seconds = // convert interval to seconds
start timer with 1 second period
actionPerformed() {
seconds--;
if (seconds == 0) {
stop timer
do whatever we were waiting for
else {
convert seconds to HH:MM:SS format and display in gui
} -
How to convert time from (hh:mm:ss) to (hhmmss) in CSV file
Hi Experts,
I have a CSV file where there is time column which displays time like hh:mm:ss
But the input I should give for loading the data is hhmmss
The amount of records that I have is more than 2 lakhs. I tried many ways to convert the time but I'm unsuccessful.
Can anyone tell me how do I convert the format please.
ThanksHi,
You can create a custom infoobject length 6 (say mytime) to read the data from csv file.
In the field routine assign the 6 character length info object to the required time IO(system time) with routine.
Inside the field routine...
result = source_fields-mytime.
The system will take care of conversion as per the user master setting.
Thanks,
Jugal.
Maybe you are looking for
-
To filter data in two dates using combo box component
Hi, I have a requirement like, i need to filter data in chart between two dates from two combo box.. From combo_box and To combo_box. I am using one QaaWS to populate LOV's into Combo box's and another QaaWS for chart data. Universe is the same one o
-
"How can I call Drill down report in 10g Without hard code user/password"
Dear All; Can I get the "Pasword" of the login user in oracle, because I want to use in report, i have get the User Name and Connecting string already but I can not get the Password. can I anybody tell me "How I get the Password in Oracle 10g" Give U
-
Date in my application is effected if i change the Region in my system
I have one problem in my applicaiton. I am getting some dates from the server side when i launch my application. But when i changed the date in Region and Language setting in control panel, the date is getting changed. If i want to stop that what do
-
Auf der Startseite ist nur das Logo..
Ich will dass auf meiner Startseite, nur ein Signet/Logo ist, und wenn man drauf clickt, kommt man rein in die seite mit den Navigationen..wie mach ich das?
-
All, I have a strange problem that I was wondering if anyone can shed any light on? I have a 4400 WLC that is authenticating users against a Cisco 3310 Guest server. Once authenticated they are not being moved from the Authentication VLAN on the CAM.