Solved

Query Date/Time field

Posted on 2013-01-02
13
364 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ServiceCenter IR Query Expressions 1 41
error in my cursor 5 41
Procedure syntax 5 41
MYSQL responding very slow 3 26
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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