Solved

Query Date/Time field

Posted on 2013-01-02
13
366 Views
Last Modified: 2013-02-08
I need to query a table where I am looking at a time stamp. The time stamp that i will be looking for will be for the month of January 2013.
 
The dates in the time stamp will be formatted like this (Date/Time):

1/1/2013 2:00:00 PM
1/3/2013 4:00:00 PM
1/17/2013 8:00:00 PM

How do I query this field so that I only get the month of January and the year of 2013.

Thanks.
0
Comment
Question by:donnie91910
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +3
13 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 417 total points
ID: 38738969
which database you are using ?

SQL server

Select Month(date_col) , Year(date_col)
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
ID: 38738973
Oracle / PL SQL

SELECT EXTRACT(month FROM date_col) from table_name
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
ID: 38738975
Oracle / PL SQL

SELECT EXTRACT(month FROM date_col) , EXTRACT(year from date_col)  from table_name
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
ID: 38738980
mysql

Select Month(date_col) , Year(date_col)
0
 

Author Comment

by:donnie91910
ID: 38738982
Microsoft Access 2003 database .
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
ID: 38738991
same
Select Month(date_col) , Year(date_col)
http://www.techonthenet.com/access/functions/date/month.php
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38739007
How about:
Select Format(date_col, "mmmm yyyy")

That will give you January 2013
mmm will give you Jan
mm will give you 01
0
 

Author Comment

by:donnie91910
ID: 38739028
There are other dates also:

1/1/2013 2:00:00 PM
1/3/2013 4:00:00 PM
1/17/2013 8:00:00 PM
2/11/2009 4:00:00 PM
4/21/2010 6:00:00 PM
6/21/2005 1:00:00 PM

I only want to query for the January 2013 dates.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38739033
you mean to say you want all sates for JAn 2013 , does not want formatting
try this


Select date_col from tablename

where Month(date_col) = 1 and Year(date_col) = 2013
0
 

Expert Comment

by:santoshsahoo123
ID: 38739035
select * from table where Month ( coloumn name ) =01 and year (coloumn name) =2013

Check and update if it s working.
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 83 total points
ID: 38739036
Select Format(date_col, "mmmm yyyy") From NameOfTable Where Format(date_col,"yyyy mm") = "2013 01"
0
 
LVL 5

Expert Comment

by:jaiminpsoni
ID: 38739766
select to_char(<date_col>, 'mm/dd/yyyy hh:mi:ss AM') from <NameOfTable> where to_char(<date_col>, 'mmyyyy') = '012013';
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 38842875
[[date-field] between [low-date] and [high-date]

see: http://www.youtube.com/watch?v=TFXzGdTSfTg

note, generally in sql: "between ... and ..." is the equivalent of:

[date-field] >= [low-date] and [date-field] <= [high-date]
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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