Sunday, February 19, 2012

CONVERT IN SELECT

Is it possible to covert a smalldatetime in a select statement using a
regular expression of some kind?
My dates are stored as:
7/30/2005 6:58:00 PM
I need to sort and group the dates by hour but I need to continue to store
the minute. Can I envoke the use of a regular expression in a convert
function? If that's possible, could someone post an example? I don't know
much about regular expressions in SQL.
Ian O'Betz
Clear Results Sytem Operator
www.clearresults.netSee http://www.karaszi.com/SQLServer/info_datetime.asp
"Ian O'Betz" <sysopNUNYO@.SPAMclearresults.net> wrote in message
news:uWonvk$mFHA.3656@.TK2MSFTNGP09.phx.gbl...
> Is it possible to covert a smalldatetime in a select statement using a
> regular expression of some kind?
> My dates are stored as:
> 7/30/2005 6:58:00 PM
> I need to sort and group the dates by hour but I need to continue to store
> the minute. Can I envoke the use of a regular expression in a convert
> function? If that's possible, could someone post an example? I don't know
> much about regular expressions in SQL.
> --
> Ian O'Betz
> Clear Results Sytem Operator
> www.clearresults.net
>
>|||Hi Ian
Probably you are looking for:
SELECT <Firlds>, CONVERT( varchar(8),<date_field>,108 )
FROM <table>
ORDER BY datepart(hh,<date_field> )
Please let me know if you would like to know anything else.
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Ian O'Betz" wrote:

> Is it possible to covert a smalldatetime in a select statement using a
> regular expression of some kind?
> My dates are stored as:
> 7/30/2005 6:58:00 PM
> I need to sort and group the dates by hour but I need to continue to store
> the minute. Can I envoke the use of a regular expression in a convert
> function? If that's possible, could someone post an example? I don't know
> much about regular expressions in SQL.
> --
> Ian O'Betz
> Clear Results Sytem Operator
> www.clearresults.net
>
>|||I forgot to mention this in my first posting, but I need the date as:
7/30/2005 6:00 PM if the actual date is 7/30/2005 6:58 PM
Ian O'Betz
Clear Results Sytem Operator
www.clearresults.net
"Chandra" <chandra@.discussions.microsoft.com> wrote in message
news:6E3E1C6E-06F1-4D5E-9EFB-2D926D0CB459@.microsoft.com...
Hi Ian
Probably you are looking for:
SELECT <Firlds>, CONVERT( varchar(8),<date_field>,108 )
FROM <table>
ORDER BY datepart(hh,<date_field> )
Please let me know if you would like to know anything else.
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Ian O'Betz" wrote:

> Is it possible to covert a smalldatetime in a select statement using a
> regular expression of some kind?
> My dates are stored as:
> 7/30/2005 6:58:00 PM
> I need to sort and group the dates by hour but I need to continue to store
> the minute. Can I envoke the use of a regular expression in a convert
> function? If that's possible, could someone post an example? I don't know
> much about regular expressions in SQL.
> --
> Ian O'Betz
> Clear Results Sytem Operator
> www.clearresults.net
>
>|||Perfect, using DateAdd() was my solution. thanks for your help.
Ian O'Betz
Clear Results Sytem Operator
www.clearresults.net
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uxxjwr$mFHA.3380@.TK2MSFTNGP12.phx.gbl...
See http://www.karaszi.com/SQLServer/info_datetime.asp
"Ian O'Betz" <sysopNUNYO@.SPAMclearresults.net> wrote in message
news:uWonvk$mFHA.3656@.TK2MSFTNGP09.phx.gbl...
> Is it possible to covert a smalldatetime in a select statement using a
> regular expression of some kind?
> My dates are stored as:
> 7/30/2005 6:58:00 PM
> I need to sort and group the dates by hour but I need to continue to store
> the minute. Can I envoke the use of a regular expression in a convert
> function? If that's possible, could someone post an example? I don't know
> much about regular expressions in SQL.
> --
> Ian O'Betz
> Clear Results Sytem Operator
> www.clearresults.net
>
>

No comments:

Post a Comment