Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date Problems

Posted on 2009-05-20
3
Medium Priority
?
178 Views
Last Modified: 2012-05-07
Afternoon,

I have a date in my database that is dd/mm/yyyy and I want to be able to in my vb.net program get the first day and last day of current month.

How can I do this?

SELECT * FROM tblPLUSales WHERE siteid = '1' and datestamp = 'startofmonth' between datestamp = 'endofmonth'
0
Comment
Question by:richard_gar
[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
3 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 24433107
Mmm... poorly explained. Explain your problem better, please. What do you want? An SQL sentence? VB.net code? What type of field stores the date value?
0
 

Author Comment

by:richard_gar
ID: 24433120
all I want to know is how to get in vb.net code the start of current month and the end of the current month.

01/05/2009 - 31/05/2009
0
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24433153
Use the following to get the date range for the current month, and use them as the parameters in the query.
Assuming you're using the System.Data.SqlClient namespace, but the same applies for any adapters.
Dim startDate As New DateTime(DateTime.Today.Year, DateTime.Today.Month, 1)
Dim endDate As DateTime = startDate .AddMonths(1).AddDays(-1)
 
Dim query As New SqlCommand("SELECT * FROM tblPLUSales WHERE siteid = '1' " & _
  "AND datestamp BETWEEN @startDate AND @endDate", sqlConn)
query.Parameters.AddWithValue("startDate", startDate)
query.Parameters.AddWithValue("endDate", endDate)

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

664 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