Solved

Query Date/Time field

Posted on 2013-01-02
13
365 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
Independent Software Vendors: 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 48

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

739 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