|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 09, 2008 4:07 AM
Points: 17,
Visits: 60
|
|
Hi,
I need to convert a date object into its integer representation in SQL server 2005.
Can anybody throw some light on this ASAP ?
Thanks Vijoy
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, February 28, 2013 1:54 AM
Points: 1,325,
Visits: 1,376
|
|
Hello,
Try: Convert(Char(8), GetDate(), 112)
Is that is the output that you need?
Regards,
John Marsh
www.sql.lu SQL Server Luxembourg User Group
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
or is it what you are looking for?
select cast(getdate() as int) /* 39717 */ select cast(39717 as datetime) /* 2008-09-28 00:00:00.000 */
.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 09, 2008 4:07 AM
Points: 17,
Visits: 60
|
|
Guys,Thanks for the replies.
What i need is an integer representation of a date say 1/9/2008 converted into seconds to be inserted into the database.
The output of a date value (1/9/2008) being inserted into the DB should be somewhat like 1220......
Awaiting your reply.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
Could you explain what exactly you are trying to achieve? Probably you may not need to do what you are trying to do now.
SQL Server stores a DATETIME value internally as two 4 byte integers. The first integer stores the number of days since 1900-01-01 and the second integer stores the number of milliseconds since midnight.
So, you may not need to do an additional conversion by yourself.What are you trying to achieve?
.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 09, 2008 4:07 AM
Points: 17,
Visits: 60
|
|
Sorry for the confusion.
I need to compare a date value that is stored in the DB via Java like this
--> "" + (cal.getTime().getTime()/1000)
So for comparing at run time i need to convert my date object (1/9/2008) as a millisecond value so that i can compare it with the DB value.
Are you able to understand my problem now ?
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
So what is the exact output you are expecting from this date value?
.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 09, 2008 4:07 AM
Points: 17,
Visits: 60
|
|
| I need the output as 1215714600 which is an int value of the date converted into milliseconds
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
What is the formula you used to get this number?
.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Thursday, March 14, 2013 4:15 AM
Points: 3,240,
Visits: 4,960
|
|
For such value, u need a Cut OFF date, from onwards, you can calculate the miiseconds till the required date, for example, FirstDate = getdate() - 1 Seconddate = getdate() Now, you can calculate teh milliseconds based on the difference of two dates as, lets say, if the difference is 1, then 24 hours = 24*60 Minutes = 24*60*60 seconds = 24*60*60*1000 milliseconds
Atif Sheikh
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sometimes, winning is not an issue but trying. You can check my BLOG here
|
|
|
|