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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get date only from a date datetime stamp

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/YYYY

How to write sql query
I mean the result should be like 10/30/2006.

thnx
shaji

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-30 : 06:07:53
Either

SELECT CONVERT(varchar, dateVariable, 101)

or

SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2006-10-30 : 06:31:20
Thanks,

But here is a problem
when I execute like this
Dim todayDate
todayDate = 10/30/2006
' Case 1
SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0) = todayDate
The result is getting false means zero

at same way if I execute like this
' Case 2
SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0) = 10/30/2006
The result is getting True means One

What is the wrong here

In the case1, I just compared with a variable
In case2, Just compared direct value, with out using a variable

Could you pls help me!

Shaji

quote:
Originally posted by Peso

Either

SELECT CONVERT(varchar, dateVariable, 101)

or

SELECT DATEADD(day, DATEDIFF(day, 0, dateVariable), 0)


Peter Larsson
Helsingborg, Sweden

Go to Top of Page

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 Larsson
Helsingborg, Sweden
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-30 : 06:48:26
What Peso said, but in case it helps: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Getting%20the%20date%20portion%20of%20a%20datetime%20value

Kristen
Go to Top of Page

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")
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -