Ask a Question related to ASP.NET General, Design and Development.
-
Ante Perkovic #1
datetime class: setting day, month...
Hi,
How to declare datetime object and set it to my birthday, first or
last day of this month or any other date.
I can't find any examples in VS.NET help!
BTW, what is the difference between date and datetime classes?
Please, help
Ante
Ante Perkovic Guest
-
problem with setting up a default value for a datetime variable
OK, I am using MySQL Administrator 1.1.9 and MySQL 5.0.19 on Windows XP Pro. I am setting up a table which I will routinely populate by uploading... -
Problem setting and accessing class members
Hello, I have the following piece of php code: <code snippet> class Section { var $id; var $name; var $color; -
setting variables inside a php class
I am trying to change the value of a variable inside a class from one of its functions rather than the constructor, but it doesn't seem to work. ... -
to convert a month to previous month
How to convert a month to previous month in a very easy way? For example, I have AUGUST, but I want JULY to return. Thanks. *** Sent via... -
Trouble setting the web.config to use my class
Hey Everyone, I am building a store application that is on an unsecured server. We got one of those shared certificates that takes you from (ex.... -
Paul #2
Re: datetime class: setting day, month...
In VB.NET...
Dim dtBirthday as DateTime = "6 November 1981 00:00"
I think the difference between the 2 classes are their precision. Date
class literally just holds the date (6 Novemebr 1981), whereas the DateTime
class holds (6 November 1981 13:42). I imagine imagine it's to do with how
much memory is reserved. I might be talking rubbish, it's just one of those
things I took for granted.
Paul
"Ante Perkovic" <albirejo_minus_j@vip.hr> wrote in message
news:toqrfvsiq84uu4v45ob7akek9hpa7p99ho@4ax.com...> Hi,
>
> How to declare datetime object and set it to my birthday, first or
> last day of this month or any other date.
>
> I can't find any examples in VS.NET help!
>
> BTW, what is the difference between date and datetime classes?
>
> Please, help
>
> Ante
Paul Guest
-
Ante Perkovic #3
Re: datetime class: setting day, month...
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message news:<e5n1TBfPDHA.2636@TK2MSFTNGP10.phx.gbl>...
....> Dim birthday As New DateTime(2003, 6, 28)....> Dim birthday As DateTime = #6/28/2003#
Yes, thanks.> Hope this helps
> Jay
But, I still don't know how to easily set date to the first day of
this month (if I don't know which is the current month).
I need something like this:
Dim begginingOfThisMonth As Date = DateTime.Today.setDay(1)
Is there an easy way to do this?
> > How to declare datetime object and set it to my birthday, first or
> > last day of this month or any other date.Ante Perkovic Guest
-
Ante Perkovic #4
Re: datetime class: setting day, month...
"Chris Becker" <slolife@hotmail.com> wrote in message news:<#rJv2G2PDHA.2636@TK2MSFTNGP10.phx.gbl>...
Thanks, Chris> Here's a some functions I wrote. There may be faster ways to do this:
>
> /// <summary>
> /// Determines the first date of the month/year specified
> /// </summary>
> /// <param name="date">Any DateTime value that is in the month
> desired</param>
> /// <returns>A DateTime value of the first date of the month
> specified</returns>
> static public DateTime GetFirstDateOfMonth(DateTime date)
> {
> return (DateTime.Parse(date.Month.ToString() + "/01/" +
> date.Year.ToString()));
> } ...
Cool :), but M$ should have done this instead of You!
Thanks,
Ante
Ante Perkovic Guest
-
MikeB #5
Re: datetime class: setting day, month...
You might want to use one of DateTime's constructors instead of parsing the
date strings. This will certainly be faster, and more importantly will
insulate your code from variations in different cultures' date formats.
For example:
static public DateTime GetFirstDateOfMonth(DateTime date) {
return (new DateTime( date.Year, date.Month, 1));
}
static public DateTime GetLastDateOfMonth( DateTime date) {
return (new DateTime( date.Year, date.Month,
DateTime.DaysInMonth( date.Year, date.Month)));
}
"Chris Becker" <slolife@hotmail.com> wrote in message
news:#rJv2G2PDHA.2636@TK2MSFTNGP10.phx.gbl...DateTime.DaysInMonth(year,> Here's a some functions I wrote. There may be faster ways to do this:
>
> /// <summary>
> /// Determines the first date of the month/year specified
> /// </summary>
> /// <param name="date">Any DateTime value that is in the month
> desired</param>
> /// <returns>A DateTime value of the first date of the month
> specified</returns>
> static public DateTime GetFirstDateOfMonth(DateTime date)
> {
> return (DateTime.Parse(date.Month.ToString() + "/01/" +
> date.Year.ToString()));
> }
>
> /// <summary>
> /// Determines the first date of the month/year specified
> /// </summary>
> /// <param name="Month">Number of month (1 - 12) desired</param>
> /// <param name="Year">Year (YYYY) of month desired</param>
> /// <returns>A DateTime value of the first date of the month
> specified</returns>
> static public DateTime GetFirstDateOfMonth(int month, int year)
> {
> return (DateTime.Parse(month.ToString() + "/01/" + year.ToString()));
> }
>
> /// <summary>
> /// Determines the last date of the month/year specified
> /// </summary>
> /// <param name="date">Any DateTime value that is in the month
> desired</param>
> /// <returns>A DateTime value of the last date of the month
> specified</returns>
> static public DateTime GetLastDateOfMonth(DateTime date)
> {
> return (DateTime.Parse(date.Month.ToString() + "/" +
> DateTime.DaysInMonth(date.Year, date.Month).ToString() + "/" +
> date.Year.ToString()));
> }
>
> /// <summary>
> /// Determines the last date of the month/year specified
> /// </summary>
> /// <param name="Month">Number of month (1 - 12) desired</param>
> /// <param name="Year">Year (YYYY) of month desired</param>
> /// <returns>A DateTime value of the last date of the month
> specified</returns>
> static public DateTime GetLastDateOfMonth(int month, int year)
> {
> return (DateTime.Parse(month.ToString() + "/" +> month).ToString() + "/" + year.ToString()));
> }
>
> "Ante Perkovic" <anteperkovic@vip.hr> wrote in message
> news:f7ead98e.0306290342.1620f08e@posting.google.c om...> message news:<e5n1TBfPDHA.2636@TK2MSFTNGP10.phx.gbl>...> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in>> > ...> > > Dim birthday As New DateTime(2003, 6, 28)> > ...> > > Dim birthday As DateTime = #6/28/2003#
> >> >> > > Hope this helps
> > > Jay
> > Yes, thanks.
> >
> > But, I still don't know how to easily set date to the first day of
> > this month (if I don't know which is the current month).
> >
> > I need something like this:
> > Dim begginingOfThisMonth As Date = DateTime.Today.setDay(1)
> >
> > Is there an easy way to do this?
> >
> >> > > > How to declare datetime object and set it to my birthday, first or
> > > > last day of this month or any other date.
>
MikeB Guest
-
Chris Becker #6
Re: datetime class: setting day, month...
I noticed that too when I looked at the code again to post the message. I
have changed it to the same code you posted. Thanks MikeB
I also thought I'd post another piece of code that might be helpful when
working with dates:
/// <summary>
/// Determine which week of the month the specified date is in
/// </summary>
/// <param name="date">The date to determine the week of the month</param>
/// <returns>The week of the month that the date occurs in</returns>
static public int GetWeekOfMonth(DateTime date)
{
DateTime pos = GetFirstDateOfMonth(date);
int rank = 1;
while (pos < date)
{
pos = pos.AddDays(7);
++rank;
}
if (pos > date)
--rank;
return (rank);
}
"MikeB" <mailbox.google@mailnull.com> wrote in message
news:etMGDCCQDHA.3088@TK2MSFTNGP10.phx.gbl...the> You might want to use one of DateTime's constructors instead of parsingor> date strings. This will certainly be faster, and more importantly will
> insulate your code from variations in different cultures' date formats.
>
> For example:
>
> static public DateTime GetFirstDateOfMonth(DateTime date) {
> return (new DateTime( date.Year, date.Month, 1));
> }
>
> static public DateTime GetLastDateOfMonth( DateTime date) {
> return (new DateTime( date.Year, date.Month,
> DateTime.DaysInMonth( date.Year, date.Month)));
> }
>
>
>
> "Chris Becker" <slolife@hotmail.com> wrote in message
> news:#rJv2G2PDHA.2636@TK2MSFTNGP10.phx.gbl...> DateTime.DaysInMonth(year,> > Here's a some functions I wrote. There may be faster ways to do this:
> >
> > /// <summary>
> > /// Determines the first date of the month/year specified
> > /// </summary>
> > /// <param name="date">Any DateTime value that is in the month
> > desired</param>
> > /// <returns>A DateTime value of the first date of the month
> > specified</returns>
> > static public DateTime GetFirstDateOfMonth(DateTime date)
> > {
> > return (DateTime.Parse(date.Month.ToString() + "/01/" +
> > date.Year.ToString()));
> > }
> >
> > /// <summary>
> > /// Determines the first date of the month/year specified
> > /// </summary>
> > /// <param name="Month">Number of month (1 - 12) desired</param>
> > /// <param name="Year">Year (YYYY) of month desired</param>
> > /// <returns>A DateTime value of the first date of the month
> > specified</returns>
> > static public DateTime GetFirstDateOfMonth(int month, int year)
> > {
> > return (DateTime.Parse(month.ToString() + "/01/" + year.ToString()));
> > }
> >
> > /// <summary>
> > /// Determines the last date of the month/year specified
> > /// </summary>
> > /// <param name="date">Any DateTime value that is in the month
> > desired</param>
> > /// <returns>A DateTime value of the last date of the month
> > specified</returns>
> > static public DateTime GetLastDateOfMonth(DateTime date)
> > {
> > return (DateTime.Parse(date.Month.ToString() + "/" +
> > DateTime.DaysInMonth(date.Year, date.Month).ToString() + "/" +
> > date.Year.ToString()));
> > }
> >
> > /// <summary>
> > /// Determines the last date of the month/year specified
> > /// </summary>
> > /// <param name="Month">Number of month (1 - 12) desired</param>
> > /// <param name="Year">Year (YYYY) of month desired</param>
> > /// <returns>A DateTime value of the last date of the month
> > specified</returns>
> > static public DateTime GetLastDateOfMonth(int month, int year)
> > {
> > return (DateTime.Parse(month.ToString() + "/" +> > month).ToString() + "/" + year.ToString()));
> > }
> >
> > "Ante Perkovic" <anteperkovic@vip.hr> wrote in message
> > news:f7ead98e.0306290342.1620f08e@posting.google.c om...> > message news:<e5n1TBfPDHA.2636@TK2MSFTNGP10.phx.gbl>...> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in> > > > Dim birthday As New DateTime(2003, 6, 28)
> > > ...
> > > > Dim birthday As DateTime = #6/28/2003#
> > > ...
> > >
> > > > Hope this helps
> > > > Jay
> > >
> > > Yes, thanks.
> > >
> > > But, I still don't know how to easily set date to the first day of
> > > this month (if I don't know which is the current month).
> > >
> > > I need something like this:
> > > Dim begginingOfThisMonth As Date = DateTime.Today.setDay(1)
> > >
> > > Is there an easy way to do this?
> > >
> > >
> > > > > How to declare datetime object and set it to my birthday, first>> >> > > > > last day of this month or any other date.
> >
>
Chris Becker Guest
-
Ante Perkovic #7
Re: datetime class: setting day, month...
"MikeB" <mailbox.google@mailnull.com> wrote in message news:<etMGDCCQDHA.3088@TK2MSFTNGP10.phx.gbl>...
This sounds simple enough.> You might want to use one of DateTime's constructors instead of parsing the
> date strings. This will certainly be faster, and more importantly will
> insulate your code from variations in different cultures' date formats.
>
> For example:
>
> static public DateTime GetFirstDateOfMonth(DateTime date) {
> return (new DateTime( date.Year, date.Month, 1));
> }
>
> static public DateTime GetLastDateOfMonth( DateTime date) {
> return (new DateTime( date.Year, date.Month,
> DateTime.DaysInMonth( date.Year, date.Month)));
> }
Thanks to all of you :)
Ante
Ante Perkovic Guest



Reply With Quote

