Convert millisecond time value to date
If i have a millisecond time value, say long timeValue, how do I convert this value to a time and a date?
Or directly set a new date using the constructor
Date(long date)
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
N.B. - Note that the Date class method to set a date from a long is:
setTime(long time)
Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
setTimeInMillis() is a Calendar method , only.
Similar Messages
-
Hi Pros,
I have a table in my oracle database, lets say TableA having a cloumn, say ColumnA with data type as DATE.
Now, inside my JDBC code, I fire a query which returns number of coulmns in a ResultSet (Including the one having DATE datatype).
When I fetch the value of 'ColumnA' column while iterating the resultset, I get a value of type java.sql.Date.
Now on UI side I need to display date and time value from this coulmn in a format dd-mm-yy hh:mm:ss, I used SimpleDateFormat to do that
but the Date on UI shows a date and time value with time value set to 00:00:00 for every row which has been fetch by the query.
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String dateAndTimeAsString = formatter.format(resultSet.getDate("CREATION_DATETIME"))The thing is can see the proper time values in database table, but it seems it is being skipped somhow.
I also tried convetring java.sal.Date to java.uitl.Date using following code format , but still the same results........
java.util.Date utilDate = new java.util.Date((resultSet.getDate("CREATION_DATETIME")).getTime();then converted this Date into string using SimpleDateFormt.format() method, but still did not hit the spot :(
String dateAndTimeAsString = formatter.format(utilDate);Any idea ? how can i achive this .................
Thanks in advance..........marathaWarrior wrote:
You are right, I should have tried it before replying,
But the thing is for a single line of change in code , it takes nearly an hour to re-build the project (and there is no short cut as code builds so many dependent jars). Hope you can understand. Any way I will give it a try.I glad you got it working.
You don't necessarily have to re-build your entire application to try something.
The next time you are in a similar situation try making a little test app that just does what you want to test. -
How to convert a string value to date
Dear All,
I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
but when i try to convert the variable to date value, I am getting the error as below.
Please help me......
PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
PS C:\script> $passwordSetDate
PasswordLastSet
7/15/2014 8:17:24 PM
PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
Cannot find an overload for "ParseExact" and the argument count: "3".
At line:1 char:1
+ $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)Dear All,
I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
but when i try to convert the variable to date value, I am getting the error as below.
Please help me......
PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
PS C:\script> $passwordSetDate
PasswordLastSet
7/15/2014 8:17:24 PM
PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
Cannot find an overload for "ParseExact" and the argument count: "3".
At line:1 char:1
+ $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
In your post you ask how to convert a string value to a date. The value returned from the Get-AdUser is already a date. It does not need to be converted.
Bill has sshown one way to convert a date to a string and there are other methods. You need to clarify your question.
If you are really trying ot convert strings to dates then you can start with this:
[datetime]'01/21/1965 13:33:23'
Most date strings aer autodetected by the class.
¯\_(ツ)_/¯ -
Conversion failed when converting the varchar value to data type int
Hi, I am unable to resolve this error and would like some assistance please.
The below query produces the following error message -
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NCPR' to data type int.
Select Pc2.Assess,
Select Pc1.Title
From Pc1
Where Pc1.Assess = Pc2.Assess
) [Title]
From Pc2
However, when I run the query below I get the results shown in the image . Ie. nothing. Pc1 & Pc2 are aliases and are the same table and the assess field is an int. I found NCPR in one cell but that column (prop) is not used in the query. The table
is nearly 25k rows.
SELECT * FROM Pc1 WHERE Pc1.Assess LIKE '%NCPR%' OR ISNUMERIC(Pc1.Assess) = 0
Thank youWHERE ISNUMERIC(id) = 1 and there are obviously no 'NCPR' records in the view as per my previous post.
That is a bad assumption - SQL Server does not have to evaluate the query in the order you are expecting it to.
Take this simple example
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
(3 row(s) affected)
col1
1
2
(2 row(s) affected)
compare to
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
WHERE col1 = 1
(3 row(s) affected)
col1
1
Msg 245, Level 16, State 1, Line 8
Conversion failed when converting the varchar value 'NaN' to data type int. -
Conversion failed when converting the varchar value to data type int error
Hi, I am working on a report which is off of survey information and I am using dynamic pivot on multiple columns.
I have questions like Did you use this parking tag for more than 250 hours? If yes specify number of hours.
and the answers could be No, 302, 279, No and so on....
All these answers are of varchar datatype and all this data comes from a partner application where we consume this data for internal reporting.
When I am doing dynamic pivot I get the below error.
Error: Conversion failed when converting the varchar value 'No' to data type int.
Query
DECLARE @Cols1 VARCHAR(MAX), @Cols0 VARCHAR(MAX), @Total VARCHAR(MAX), @SQL VARCHAR(MAX)
SELECT @Cols1 = STUFF((SELECT ', ' + QUOTENAME(Question) FROM Question GROUP BY Question FOR XML PATH('')),1,2,'')
SELECT @Cols0 = (SELECT ', COALESCE(' + QUOTENAME(Question) + ',0) as ' + QUOTENAME(Question) FROM Question GROUP BY Question FOR XML PATH(''))
SET @SQL = 'SELECT QID, QNAME' + @Cols0 + '
FROM (SELECT QID, QNAME, ANSWERS, Question
FROM Question) T
PIVOT (MAX(ANSWERS) FOR Question IN ('+@Cols1+')) AS P'
EXECUTE (@SQL)
I am using SQL Server 2008 R2.
Please guide me to resolve this.
Thanks in advance..........
Ionecreate table questions (QID int, QNAME varchar(50), ANSWERS varchar(500), Question varchar(50))
Insert into questions values(1,'a','b','c'), (2,'a2','b2','c2')
DECLARE @Cols1 VARCHAR(MAX), @Cols0 VARCHAR(MAX), @Total VARCHAR(MAX), @SQL VARCHAR(MAX)
SELECT @Cols1 = STUFF((SELECT ', ' + QUOTENAME(Question) FROM Questions GROUP BY Question FOR XML PATH('')),1,2,'')
SELECT @Cols0 = (SELECT ', COALESCE(' + QUOTENAME(Question) + ',''0'') as ' + QUOTENAME(Question) FROM Questions GROUP BY Question FOR XML PATH(''))
SET @SQL = 'SELECT QID, QNAME' + @Cols0 + '
FROM (SELECT QID, QNAME, ANSWERS, Question
FROM Questions) T
PIVOT (MAX(ANSWERS) FOR Question IN ('+@Cols1+')) AS P'
EXECUTE (@SQL)
drop table questions -
Converting the string value to data format
Hello Everyone,
Please guide me in converting the value to date format.
from source i'm getting the value (which is acchally a data value) '20070730'.
I need this value to be in date format '2007/07/30'
Please help me in getting it done.
thank youHi
Code Snippetselect cast('20070730' as datetime)
Note : beware of collation used in your SQL instance or your database.
Jean-Pierre -
Thank you for your help!!!
I've created a stored procedure to return results as xml. I'm having trouble figuring out why I'm getting the error message "Conversion failed when converting the nvarchar value '<tr>.....'
to data type int. It seems like the system doesn't know that I'm returning a string... Or, I'm doing something that I just don't see.
ALTER PROCEDURE [dbo].[p_getTestResults]
@xml NVARCHAR(MAX) OUTPUT
AS
BEGIN
CREATE TABLE #Temp
[TestNameId] int,
[MaxTestDate] [DateTime],
[Name] [nvarchar](50),
[Duration] [varchar](10)
DECLARE @body NVARCHAR(MAX)
;WITH T1 AS
SELECT DISTINCT
Test.TestNameId
, replace(str(Test.TotalTime/3600,len(ltrim(Test.TotalTime/3600))+abs(sign(Test.TotalTime/359999)-1)) + ':' + str((Test.TotalTime/60)%60,2)+':' + str(Test.TotalTime%60,2),' ','0') as Duration
,MaxTestDate = MAX(TestDate) OVER (PARTITION BY TM.TestNameId)
,TestDate
,TM.Name
,Test.TotalTime
,RowId = ROW_NUMBER() OVER
PARTITION BY
TM.TestNameId
ORDER BY
TestDate DESC
FROM
Test
inner join TestName TM on Test.TestNameID = TM.TestNameID
where not Test.TestNameID in (24,25,26,27)
INSERT INTO #Temp
SELECT
T1.TestNameId
,T1.MaxTestDate
,T1.[Name]
,T1.Duration
FROM
T1
WHERE
T1.RowId = 1
ORDER BY
T1.TestNameId
SET @body ='<html><body><H3>TEST RESULTS INFO</H3>
<table border = 1>
<tr>
<th> TestNameId </th> <th> MaxTestDate </th> <th> Name </th> <th> Duration </th></tr>'
SET @xml = CAST((
SELECT CAST(TestNameId AS NVARCHAR(4)) as 'td'
, CAST([MaxTestDate] AS NVARCHAR(11)) AS 'td'
, [Name] AS 'td'
, CAST([Duration] AS NVARCHAR(10)) AS 'td'
FROM #Temp
ORDER BY TestNameId
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body = @body + @xml +'</table></body></html>'
DROP TABLE #Temp
RETURN @xml
END
closlYour dont need RETURN inside SP as you've declared @xml already as an OUTPUT parameter. Also you can RETURN only integer values using RETURN statement inside stored procedure as that's default return type of SP.
so just remove RETURN statement and it would work fine
To retrieve value outside you need to invoke it as below
DECLARE @ret nvarchar(max)
EXEC dbo.[P_gettestresults] @ret OUT
SELECT @ret
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Convert utc time to oracle date
Hi ,
I want to compare two dates the date passed in will be say '0303090000000' with a dur_date I have in the table X .
dur_date is a DATE type ...
How can i do this in oracle?Hi,
Should I not use to_char(dur_date 'yyyy-mm-dd hh24:mi:ss') ?No, you should do it the other way around, convert passed string into DATE.
But what format is this string in?
'0303090000000'It seems to be one character too long, and it is unclear what it means. Depending of what meaning you put into it, it can be either one of these:
SQL> alter session set nls_date_format = 'dd-MON-rrrr'
Session altered.
SQL> select to_date('030309000000', 'ddmmyyhh24miss') date_ from dual
union all
select to_date('030309000000', 'ddmmrrhh24miss') from dual
union all
select to_date('030309000000', 'mmddyyhh24miss') from dual
union all
select to_date('030309000000', 'mmddrrhh24miss') from dual
union all
select to_date('030309000000', 'yyddmmhh24miss') from dual
union all
select to_date('030309000000', 'rrddmmhh24miss') from dual
DATE_
03-MAR-2009
03-MAR-2009
03-MAR-2009
03-MAR-2009
03-SEP-2003
03-SEP-2003
6 rows selected.But probably not 'yyyy-mm-dd hh24:mi:ss'
Regards
Peter -
Converting epoch time to a date
Anyone know of a function to do this. I cant find any in the api and my searches bring up nothing.
You can create your class that extends GregorianCalendar.Then you can access the protected class in super class. Following codes are what I write to handle this problem. Hope it help.
import java.util.*;
public class Test10{
public Test10(){
init();
public void init(){
MyCalendar calendar1 = new MyCalendar();
calendar1.set(2002, 07, 12);
System.out.println("time in epoch: " + calendar1.getTimeInMillis());
public static void main(String[] str)
new Test10();
private class MyCalendar extends GregorianCalendar
public MyCalendar(){
super();
public long getTimeInMillis()
return super.getTimeInMillis(); -
Convert an integer value that was created with the Excel DATEVALUE formula to a valid date?
Hello everyone,
How can I convert an integer value that was created with the Excel DATEVALUE formula to a valid date in SSIS?
Is this even possible?
For example:
=DATEVALUE("8/22/2008") will format the cell to display 39682.
Reading the column as a string to get the int value (39682) - how can I turn this into a valid date using SSIS and then importing the real date to sql server?
Thank you!You can use Script component for this and convert your integer values to Date. An example here is following:
CultureInfo provider = CultureInfo.InvariantCulture;
string dateString = "08082010";
string format = "MMddyyyy";
DateTime result = DateTime.ParseExact(dateString, format, provider);
Source: http://stackoverflow.com/questions/2441405/converting-8-digit-number-to-datetime-type
Vikash Kumar Singh || www.singhvikash.in -
Wait ms Timer Multiple returning inaccurate timer value
We are using the Wait Until Next ms Multiple Timer value to set the interval that data is recorded to a file. Because of Windows 2000 time indeterminancy, the Wait Until Next ms Multiple Timer value is written to file, along with the data point, and is used to calculate the derivative between two successive points. With a delay of 1 sec (1000 ms), the actual interval ranges from 1025 to 1035 ms. At several (random!) points during the acquisition, the difference between successive ms values is considerably smaller than 1000 ms (e.g. 15-25 ms). The following difference compensates for the previous error e.g. the difference will be 2025-2055ms. The data that we are recording is a smoothly continuou
s function and it appears that the sample is actually recorded at approximately 1000 plus ms. Thus it appears that the Wait Until Next ms Multiple waits the appropriate amount of time to record the data point, but outputs an erroneous ms timer value. We added a ms Timer function to the VI, which also experienced a similar glitch. This glitch does not correspond to the wraparound point; it occurs at approximately 60 to 130 sec intervals. We took the timing code only (no data acquisition, etc) and created a VI that wrote just the time values to a file. This is attached, along with the generated data in a spreadsheet. This consistently executed every 1000 ms but occasionally confused the intervals by 1-57 ms. The pattern was reversed from the previous problem by having a long interval and then a short interval. Any insight would be greatly appreciated!
Attachments:
CollectingSampleData.vi 47 KB
Create_XCoord.vi 25 KB
sampledata.xls 91 KBAgree completely but why can't LV provide access to the windows multimedia
timer like LabWindows does? Provide me a timer, I can start/stop by changing
its properties and run that in a separate thread. Obviously if I have
another thread starving this timer thread, it won't help much but using
multi-media timer, I have seen very good results on a windows2000 machine.
Now win95/98 and derivatives are all other story.
vishi
"Al S" wrote in message
news:[email protected]..
> There are a couple of things going on that affect your results.
> 1. Windows is not a real-time operating system. As it multi-tasks,
> you have little control over when it gives time to your application.
> Loop times may vary depend
ing on what else Windows decides during that
> iteration. Especially when doing file I/O: if your disk is busy, a
> loop interation may take longer. Windows may also be doing some disk
> buffering, so occasionally a loop interation may take much longer than
> usual as the buffered data from multiple loop interations gets written
> to disk.
> 2. Wait Until Next ms Multiple doesn't garuntee equal loop times.
> With the millisecond multiple input set to 1000, if one iteration
> starts with the PC's clock at xx:xx:xx.001, Wait Until Next ms
> Multiple will wait 0.999 seconds. If an iteration starts with the
> PC's clock at xx:xx:xx.999, Wait Until Next ms Multiple will wait
> 0.001 seconds.
> 3. In your main loop, you check to see if the millisecond timer value
> * 60 equals the desired Length of Data Collection. If your loop
> doesn't execute every millisecond, you may miss the equals case and
> then your loop won't stop. You should check >= rather than just =. -
SSRS error "Conversion failed when converting the nvarchar value"
Hi folks!
After SCCM 2012 R2 upgrade, we have errors with self made reports:
An error has occurred during report processing. (rsProcessingAborted)
Cannot read the next data row for the dataset DataSet2. (rsErrorReadingNextDataRow)
Conversion failed when converting the nvarchar value '*****' to data type int.
I found several articles to see reporting services log file for possible WMI related errors, but none exists. SQL server is 2008R2, Runned mofcomp, and re-installed reporting services role, but problem remains.
I traced the dataset2 query:
SELECT
v_Collection_Alias.CollectionID ,v_Collection_Alias.Name
FROM fn_rbac_Collection(@UserSIDs) v_Collection_Alias
WHERE
v_Collection_Alias.CollectionType = 2
Any adwice is appreciated.
~Tuomas.Hi Tuomas,
What's the SQL Server version? To verify the the SQL Server version, please see
http://support.microsoft.com/kb/321185
SCCM 2012 R2 need SQL Server 2008 R2 SP1 with CU 6 or SQL Server 2008 R2 with SP2 (http://technet.microsoft.com/en-us/library/gg682077.aspx#BKMK_SupConfigSQLSrvReq).
If the SQL meets requirement, I would suggest you submit a thread to SQL forum to deal with the sql issue.
Thanks.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
Query needed for sorting by time value
Hi Folks
We have table it consists two columns like below
Job_name varchar2(50)
Scheduled_time date
The filed scheduled time keep date and time value like below
25-Jul-2009 4:00:10 AM
26-Jul-2009 4:00:01 PM
27-Jul-2009 4:00:00 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
02-Jun-2009 4:15:40 AM
We need output as sorting by time value NOT date value. Expected output to be below
25-Jul-2009 4:00:10 AM
02-Jun-2009 4:15:40 AM
27-Jul-2009 4:00:00 PM
26-Jul-2009 4:00:01 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
I am using oracle 10G
Thanks in AdvanceHere's how :
SQL> create table job_table (job_name varchar2(50) not null, scheduled_time date);
Table created.
SQL> insert into job_table
2 values ('Job_abc',to_date('25-JUL-2009 04:00:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fdw',to_date('02-JUN-2009 04:15:40','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fxj',to_date('27-JUL-2009 03:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_rjt',to_date('20-JUL-2009 14:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set nls_date_format='DD-MON-YYYY HH:MI:SS AM';
Session altered.
SQL> select job_name, scheduled_time from job_table
2 order by to_char(scheduled_time,'HH24:MI:SS');
JOB_NAME SCHEDULED_TIME
Job_fxj 27-JUL-2009 03:59:00 AM
Job_abc 25-JUL-2009 04:00:00 AM
Job_fdw 02-JUN-2009 04:15:40 AM
Job_rjt 20-JUL-2009 02:59:00 PM
SQL> -
hi mates
can any one give me the java code to convert sql time to util date?
thanks in advanceSince java.sql.Time extends java.util.Date it is a
Date. Am i right here?How about looking it up? Then you'd know.
Yes, sql.Date extends util.Date.Sorry. I'm getting screen-tired. sql.Time extends util.Date, too. But they only show the time, no date. -
Can I convert Facebook time Text to Project Siena's Date value ?
Can I convert Facebook time Text to Project Siena's Date value ?
I want to show create_time on screen by my Localtime formatted text.
Facebook time Text = 2014-07-14T11:22+0000
I want to show = 2014/07/14 18:22
My Time Zone is +09:00, Osaka/Japan.
Currently I try it by Text/Replace/Replace/Replace/Left/DateValue/+ , etc.
And I ask more simple way.
Regards,
Yoshihiro KawabataThank you Andy , and Robin, I can.
Text(TimeValue(Substitute(ThisItem!created_time,"+0000",".000Z")),"yyyy/mm/dd hh:mm")
At Facebook Albums's Gallary, I can convert from Facebook created_time to Localtime Text DateTime.
and I hope more easy way like Excel Power Query's one.
Regards,
Yoshihiro Kawabata
Maybe you are looking for
-
i went to put music on my itunes from my ipod and it deleted most of my music off of it and i dont know how to get it back. PLEASE HELP ME. :-|
-
Inbound deliveries and Shipment
Hi How does one change the quantity on an inbound delivery after the shipmwnt was created. Is this possible. Is there any other means of reducing the quantiy on the confirmations tab of a purchase order. Vishnu
-
Field label from data element (language dependent)
I have 2 development systems and am struggling to get different language from a standard sap data element. On Dev system 1 the program is: parameters: l_file1 like filename-fileintern. In the selection texts of the program I select "Dictionary r
-
How 2 password protect ducments?
i am using text edit to save most of my important information and would like to password protect them. i want that a password is required to open the file, whether on a mac or window or linux. is it possible? Neerav
-
Why does Time Machine forget "everything" after Mountain Lion update?
After updating to Mountain Lion (from Snow Leopard), I fired up my trusty external hard drive which contains my Time Machine backups (and nothing else) - of course I had run a backup right before upgrading to be sure. Two things are deeply disturbing