ziwez0
asked on
SELECT DATETIME UK to US Format
I havent had to do a select where dattime =... for a long time now (strange), but it reminded me why I hate doing them (why does the WHERE [Date] has to be different from everything else??)
Anyway, I just want to return a count based on a selected day.
string strCountYesterday = "SELECT COUNT(OID) AS RMA FROM Table WHERE dtStamp =@dtStamp_3";
DateTime dtToday = DateTime.Today;
dtToday = dtToday - new TimeSpan(1, 0, 0, 0);
string strToday = Convert.ToString(dtToday.T oShortDate String());
CultureInfo ci;
ci = CultureInfo.CreateSpecific Culture("e n-US");
DateTime dtYesterday = DateTime.Parse(strToday,ci );
ci.DateTimeFormat.ShortDat ePattern = "MM/dd/YYYY";
CommandCommandText = strCountRMAYesterday;
Command.Connection = Connection;
Command.Parameters.AddWith Value("@dt Stamp_3", Convert.ToDateTime(dtYeste rday,ci));
//more code...
//dtYesterday format 06/10/2008 00:00:00
but im still not getting any records back, what have i done wrong?
Anyway, I just want to return a count based on a selected day.
string strCountYesterday = "SELECT COUNT(OID) AS RMA FROM Table WHERE dtStamp =@dtStamp_3";
DateTime dtToday = DateTime.Today;
dtToday = dtToday - new TimeSpan(1, 0, 0, 0);
string strToday = Convert.ToString(dtToday.T
CultureInfo ci;
ci = CultureInfo.CreateSpecific
DateTime dtYesterday = DateTime.Parse(strToday,ci
ci.DateTimeFormat.ShortDat
CommandCommandText = strCountRMAYesterday;
Command.Connection = Connection;
Command.Parameters.AddWith
//more code...
//dtYesterday format 06/10/2008 00:00:00
but im still not getting any records back, what have i done wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
gauthampj:, that did the trick... could you explain this
.. WHERE cast(floor(cast(dtStamp as float)) as datetime)=@dtStamp_3";
why so much work for just getting a date???
thanks
.. WHERE cast(floor(cast(dtStamp as float)) as datetime)=@dtStamp_3";
why so much work for just getting a date???
thanks
dtStamp might have time with it in the column so
first we convert datetime into float then floor it which will give us the date component and then convert back to datetime
first we convert datetime into float then floor it which will give us the date component and then convert back to datetime
ASKER
Thank-you
try to use yyyy instead of YYYY.
Regards,
Bruce