Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2006-10-30 : 06:05:01
|
Hi,I have a date and time variable like dateVariable = '30/10/2006 12:45:36 AM'.(DD/MM/YYYY HH:MM:SS)From this variable how to fetch only the date part in the format of MM/DD/YYYYHow to write sql queryI mean the result should be like 10/30/2006.thnxshaji |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-30 : 06:07:53
|
EitherSELECT CONVERT(varchar, dateVariable, 101)orSELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0)Peter LarssonHelsingborg, Sweden |
|
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2006-10-30 : 06:31:20
|
Thanks,But here is a problem when I execute like thisDim todayDate todayDate = 10/30/2006' Case 1SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0) = todayDateThe result is getting false means zeroat same way if I execute like this ' Case 2SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0) = 10/30/2006The result is getting True means OneWhat is the wrong hereIn the case1, I just compared with a variableIn case2, Just compared direct value, with out using a variableCould you pls help me!Shaji quote: Originally posted by Peso EitherSELECT CONVERT(varchar, dateVariable, 101)orSELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0)Peter LarssonHelsingborg, Sweden
|
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-30 : 06:34:07
|
You are aware you are at a SQL forum? Where people ask Microsft SQL database related questions?It seems to me you want help with VB or VScript.Peter LarssonHelsingborg, Sweden |
|
|
Kristen
Test
22859 Posts |
|
deanheathen
Starting Member
4 Posts |
Posted - 2006-11-11 : 12:18:42
|
in VB You just need the integer portion of the date:I.E. int(date) or if you want a string style date format(date,"MM-DD-YY or your favorite format") |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-11 : 12:29:47
|
try using CDate on your todayDate.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
|
|
|
|
|
|
|