Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Query Date/Time field

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
donnie91910
Asked:
donnie91910
  • 6
  • 2
  • 2
  • +3
6 Solutions
 
Pratima PharandeCommented:
which database you are using ?

SQL server

Select Month(date_col) , Year(date_col)
0
 
Pratima PharandeCommented:
Oracle / PL SQL

SELECT EXTRACT(month FROM date_col) from table_name
0
 
Pratima PharandeCommented:
Oracle / PL SQL

SELECT EXTRACT(month FROM date_col) , EXTRACT(year from date_col)  from table_name
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Pratima PharandeCommented:
mysql

Select Month(date_col) , Year(date_col)
0
 
donnie91910Author Commented:
Microsoft Access 2003 database .
0
 
Pratima PharandeCommented:
same
Select Month(date_col) , Year(date_col)
http://www.techonthenet.com/access/functions/date/month.php
0
 
IrogSintaCommented:
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
 
donnie91910Author Commented:
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
 
Pratima PharandeCommented:
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
 
santoshsahoo123Commented:
select * from table where Month ( coloumn name ) =01 and year (coloumn name) =2013

Check and update if it s working.
0
 
IrogSintaCommented:
Select Format(date_col, "mmmm yyyy") From NameOfTable Where Format(date_col,"yyyy mm") = "2013 01"
0
 
jaiminpsoniCommented:
select to_char(<date_col>, 'mm/dd/yyyy hh:mi:ss AM') from <NameOfTable> where to_char(<date_col>, 'mmyyyy') = '012013';
0
 
PaulCommented:
[[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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now