SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


convert date object into integer


convert date object into integer

Author
Message
Vijoy Kolady
Vijoy Kolady
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 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
John H Marsh
John H Marsh
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2095 Visits: 1463
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
jacob sebastian
jacob sebastian
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1448 Visits: 2523
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
*/



.
Vijoy Kolady
Vijoy Kolady
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 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.
jacob sebastian
jacob sebastian
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1448 Visits: 2523
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?

.
Vijoy Kolady
Vijoy Kolady
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 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 ?
jacob sebastian
jacob sebastian
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1448 Visits: 2523
So what is the exact output you are expecting from this date value?

.
Vijoy Kolady
Vijoy Kolady
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 60
I need the output as 1215714600 which is an int value of the date converted into milliseconds
jacob sebastian
jacob sebastian
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1448 Visits: 2523
What is the formula you used to get this number?

.
Atif-ullah Sheikh
Atif-ullah Sheikh
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4132 Visits: 5201
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search