Solved

timestamp

Posted on 2014-09-04
6
211 Views
Last Modified: 2014-09-04
1. I want to get all records from my table where timestamp = to today's date.

Timestamp column
2014-09-04 14:08:25.243

select *from tbl_sample  where sellerCode = 'abc' and convert(char(10), TimeStamp, 112) = convert(char(10), GETDATE(), 120)

2. I have a column call Postingdate - 2014-09-01 00:00:00.000. I also want it to returns where postingdate = today's date
0
Comment
Question by:VBdotnet2005
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40304806
select *from tbl_sample  where sellerCode = 'abc' and
(
   convert(char(10), TimeStamp, 112) = convert(char(10), GETDATE(), 112) OR
   convert(char(10), postingdate , 112) = convert(char(10), GETDATE(), 112)
)
0
 

Author Comment

by:VBdotnet2005
ID: 40304842
thank you :)
0
 

Author Comment

by:VBdotnet2005
ID: 40304845
Is this common?  convert(char(10), TimeStamp, 112) = convert(char(10), GETDATE(), 112)

select convert(char(10), '2014-09-01 00:00:00.000', 112)
result = 2014-09-01

select convert(char(10), GETDATE(), 112)
result = 20140904
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40304849
http://www.blackwasp.co.uk/SQLDateTimeFormats.aspx

You can use 126 if you want to keep the dashes.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40304934
or refer to:
http://www.experts-exchange.com/Database/MS-SQL-Server/A_12315-SQL-Server-Date-Styles-formats-using-CONVERT.html

I would not recommend converting your timestamp column to varchar however, you should leave the data unconverted to take advantage of indexes. Please see this:

http://en.wikipedia.org/wiki/Sargable
0
 

Author Comment

by:VBdotnet2005
ID: 40305058
Thank you Portletpaul. Very useful.
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now