Monday, March 26, 2012

Minutes since midnight

I would like to know the number of minutes past midnight for the
system date. Is that possible?
-JohnYes, Dates are stored internally as decimal numbers where the fractional
part is just that, the time since midnight, so cast the datetime value to a
float, and extract the fractional portion , and multiply that times the
number of minutes in a day...
Select (Cast (getdate() as float) - Cast(getdate() as Int)) * 24 * 60
"John Baima" wrote:

> I would like to know the number of minutes past midnight for the
> system date. Is that possible?
> -John
>|||Thanks, that's interesting. How about
Select (Cast (getdate() as float) - round(Cast(getdate() as float), 0,
1)) * 24 * 60
instead? Yours is giving me a negative number.
-John
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote:
>Yes, Dates are stored internally as decimal numbers where the fractional
>part is just that, the time since midnight, so cast the datetime value to
a
>float, and extract the fractional portion , and multiply that times the
>number of minutes in a day...
>Select (Cast (getdate() as float) - Cast(getdate() as Int)) * 24 * 60
>"John Baima" wrote:
>|||Round will round "UP" if it's after noon...
"John Baima" wrote:

> Thanks, that's interesting. How about
> Select (Cast (getdate() as float) - round(Cast(getdate() as float), 0,
> 1)) * 24 * 60
> instead? Yours is giving me a negative number.
> -John
>
> "CBretana" <cbretana@.areteIndNOSPAM.com> wrote:
>
>|||try this:
select datediff(mi,convert(varchar(8),getdate()
,112),getdate())
dean
"John Baima" <john@.nospam.com> wrote in message
news:tsg5511f573eo7rbm31mavp76h78l7li95@.
4ax.com...
>I would like to know the number of minutes past midnight for the
> system date. Is that possible?
> -John|||Try,
select datediff(minute, convert(char(8), getdate(), 112), getdate())
go
AMB
"John Baima" wrote:

> I would like to know the number of minutes past midnight for the
> system date. Is that possible?
> -John
>|||I guess the Cast(Dattime as Int) is also rounding UP... The floor function
always gets the next lowest Integer...
Select (Cast (getDate() as float) - Floor(Cast(getdate() as float))) * 24 *
60
It's only 10:30 out here on the left coast...
"John Baima" wrote:

> Thanks, that's interesting. How about
> Select (Cast (getdate() as float) - round(Cast(getdate() as float), 0,
> 1)) * 24 * 60
> instead? Yours is giving me a negative number.
> -John
>
> "CBretana" <cbretana@.areteIndNOSPAM.com> wrote:
>
>sql

No comments:

Post a Comment