473,466 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date problem ?

I'm trying to write a simple vb function that takes a current date and
calculates for the first day of the month of that date what day of the week
it is.

I thought I could take a date object dt, use dt.Days() to return how many
days into the month, then create a date object equal to the 1st of the
month by subtracting the number of days from dt, and then use the dayofweek
method to find out what I need.
My difficulty is how create a date object that is the first day of this
month. The subtract methods need a date object or a timespan object as an
argument, but I cannot see how to set a timespan object to a certain number
of days ?
Am I being stupid here and missing the obvious ?
Apr 1 '08 #1
3 1015
"Tony B" <to***@imageproc.comschrieb
I'm trying to write a simple vb function that takes a current date
and calculates for the first day of the month of that date what day
of the week it is.

I thought I could take a date object dt, use dt.Days() to return how
many days into the month, then create a date object equal to the
1st of the month by subtracting the number of days from dt, and then
use the dayofweek method to find out what I need.
My difficulty is how create a date object that is the first day of
this month. The subtract methods need a date object or a timespan
object as an argument, but I cannot see how to set a timespan object
to a certain number of days ?
Am I being stupid here and missing the obvious ?

Private Shared Function WeekDayOfFirstDayInCurrentMonth() _
As DayOfWeek

Dim Today As Date = DateTime.Today

Return Today.AddDays(-Today.Day + 1).DayOfWeek

End Function

Usage:
MsgBox( _
Globalization.DateTimeFormatInfo.CurrentInfo.GetDa yName( _
WeekDayOfFirstDayInCurrentMonth _
) _
)
Armin
Apr 1 '08 #2
Tony B wrote:
My difficulty is how create a date object that is the first day of
this month.
I have always used something like
Dim FirstOMonth As Date = New Date(Today.Year, Today.Month, 1)
Apr 2 '08 #3
Tony,
Am I being stupid here and missing the obvious ?
Not wanting to be rude, yes.

Have the next time a look at the overloaded functions of methods (not only
this one), that will help you a lot.

Cor

Apr 3 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very clean. I've come up with some rules that I think...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
3
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.