February 27, 2008 at 9:51 am
select getdate() as todaydate, cast(getdate() as varchar) "diff format" ,cast(getdate()+1 as int) as intformat--- as convert
todaydate diff format intformat
----------------------- ------------------------------ -----------
2008-02-27 11:35:37.750 Feb 27 2008 11:35AM 39504
(1 row(s) affected)
select cast (39504 as datetime) as abc ,getdate() todaydate
abc todaydate
----------------------- -----------------------
2008-02-28 00:00:00.000 2008-02-27 11:50:28.123
(1 row(s) affected)
so i coudlnt understand the logic for the int converting to data and the date to 5 digits int plz let me know the logic over there....plz thkz in advance
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 9:57 am
when converting a number to datetime, the date portion is left of the decimal place, and the time portion is to the right of the decimal point.
I think it really is stored as a decimal, and formatted for display based on settings or convert() applied to it.
the definition is the number of days since 01/01/1900....approximately 365 x 108 years...
[font="Courier New"]
select
getdate() as TheDate,
convert(decimal(10,4),getdate()) As decimaldate
TheDate decimaldate
----------------------- ---------------------------------------
2008-02-27 11:54:39.630 39503.4963
[/font]
Lowell
February 27, 2008 at 10:02 am
Actually, it's stored as a "fixed place float"...
--Jeff Moden
Change is inevitable... Change for the better is not.
February 27, 2008 at 10:04 am
Well #77 beat me too it 😛
February 27, 2008 at 10:04 am
thkz but did it works how abt time is it the same way is it in second of the day or what format is that ???
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 10:06 am
but whats the logic is it the number of days from 1990 yr is that the one i jus want to know that logic ....
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 10:09 am
Maybe this example will help clarify. You will note the date portion is always to the left of the period. The hours/min/sec etc are on the right. Use the code below to change the current date and time into a float value the cast it back the other way.
select cast(getdate() as float) [datetime w hr_min_sec], cast(39503 as datetime) [date w 0s]
As far how the decimal represents the time, I really have no idea that's why I convert it. Maybe someone else has that answer.
February 27, 2008 at 10:14 am
kurraraghu (2/27/2008)
but whats the logic is it the number of days from 1990 yr is that the one i jus want to know that logic ....
yes, the logic is the number of days since 01/01/1900. 39503 days so far...and the right of the decimal is the portion of a day... so .5000 would be exactly have a day/12 hours, so it
39503.5000 would be 12 noon for today...
Lowell
February 27, 2008 at 10:17 am
declare @dt datetime
set @dt = '1900-01-1 00:00:00.000'
select cast(@dt as float)
----------------------
0.105555555555556
(1 row(s) affected)
here how is the time calculate is it seconds of the day or milliseconds smthng like could plz let me knoe i have got the date logic thkz to all u guys ....
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 10:18 am
thkz lowell gotch u ....n thkz to all of them...
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 10:22 am
but lowell i havea ques
select cast (39504.5023 as datetime) as abc ,getdate() todaydate
abc todaydate
----------------------- -----------------------
2008-02-28 12:03:18.720 2008-02-27 12:20:13.577
(1 row(s) affected)
so how did that 5023 converted to 12:03:18:720 ....
select cast (39504.5000 as datetime) as abc ,getdate() todaydate
abc todaydate
----------------------- -----------------------
2008-02-28 12:00:00.000 2008-02-27 12:22:14.373
(1 row(s) affected)
where as 5000 is 12:00:00:000 how is that converted
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
February 27, 2008 at 10:29 am
kurraraghu (2/27/2008)
declare @dt datetimeset @dt = '1900-01-1 00:00:00.000'
select cast(@dt as float)
----------------------
0.105555555555556
(1 row(s) affected)
here how is the time calculate is it seconds of the day or milliseconds smthng like could plz let me knoe i have got the date logic thkz to all u guys ....
No... that's not right...
declare @dt datetime
set @dt = '1900-01-1 00:00:00.000'
select cast(@dt as float)
-----------------------------------------------------
0.0
(1 row(s) affected)
--Jeff Moden
Change is inevitable... Change for the better is not.
February 27, 2008 at 10:29 am
Kurraghu - it's stored in increments of a day. so it's .5023 of a day.
So 1day = 24 hour=24*60 minutes = 24*60*60 secs,
therefore .5023*24*60*60=43398.72 sec = 723 minutes 18.72 secs = 12h3 minutes 18.72 seconds.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply