Solved

Query Date/Time field

Posted on 2013-01-02
13
360 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
  • 6
  • 2
  • 2
  • +3
13 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 417 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Oracle / PL SQL

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

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
Comment Utility
mysql

Select Month(date_col) , Year(date_col)
0
 

Author Comment

by:donnie91910
Comment Utility
Microsoft Access 2003 database .
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 417 total points
Comment Utility
same
Select Month(date_col) , Year(date_col)
http://www.techonthenet.com/access/functions/date/month.php
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 29

Expert Comment

by:IrogSinta
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Select Format(date_col, "mmmm yyyy") From NameOfTable Where Format(date_col,"yyyy mm") = "2013 01"
0
 
LVL 5

Expert Comment

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

Expert Comment

by:PortletPaul
Comment Utility
[[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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

14 Experts available now in Live!

Get 1:1 Help Now