SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get date only from a date datetime stamp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shajimanjeri
Posting Yak Master

India
179 Posts

Posted - 10/30/2006 :  06:05:01  Show Profile  Reply with Quote
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

Sweden
30212 Posts

Posted - 10/30/2006 :  06:07:53  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
179 Posts

Posted - 10/30/2006 :  06:31:20  Show Profile  Reply with Quote
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

Sweden
30212 Posts

Posted - 10/30/2006 :  06:34:07  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

United Kingdom
22403 Posts

Posted - 10/30/2006 :  06:48:26  Show Profile  Reply with Quote
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

USA
4 Posts

Posted - 11/11/2006 :  12:18:42  Show Profile  Visit deanheathen's Homepage  Reply with Quote
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

Slovenia
11750 Posts

Posted - 11/11/2006 :  12:29:47  Show Profile  Visit spirit1's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000