Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How could i datetime filed convert to number format

e.g:
C#
DateTime StartOfWeek = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek);
      DateTime EndOfLastWeek = StartOfWeek.AddDays(-1);


Thanks
Tamimun
Posted
Updated 24-May-12 2:51am
v2
Comments
[no name] 24-May-12 8:53am    
Please clarify what you are trying to accomplish.
Prasad_Kulkarni 24-May-12 8:59am    
Hi Mark, I thought that i got properly what exactly OP wants from his actual question therefore I answered here.
What I got from his eg. is all he wants the days between two days, I agree with your comment that question he mentioned and actually ask'd is far different. But I just tried to solve what he ask'd with actual example.
[no name] 24-May-12 9:16am    
Why are you answering? The question was for the OP to clarify not for you to make assumptions about what they wanted. I'm glad you can read minds and know exactly what was asked for.
Prasad_Kulkarni 24-May-12 9:21am    
:) Thank you..
but that's what for I commented above,
I just answered for his actual code snippet that's it,:(

Try this: From this link[^]
C#
public static int Weekdays(DateTime dtmStart, DateTime dtmEnd)
    {
        // This function includes the start and end date in the count if they fall on a weekday
        int dowStart = ((int)dtmStart.DayOfWeek == 0 ? 7 : (int)dtmStart.DayOfWeek);
        int dowEnd = ((int)dtmEnd.DayOfWeek == 0 ? 7 : (int)dtmEnd.DayOfWeek);
        TimeSpan tSpan = dtmEnd - dtmStart;
        if (dowStart <= dowEnd)
        {
            return (((tSpan.Days / 7) * 5) + Math.Max((Math.Min((dowEnd + 1), 6) - dowStart), 0));
        }
        return (((tSpan.Days / 7) * 5) + Math.Min((dowEnd + 6) - Math.Min(dowStart, 6), 5));
    }

Tests (each test returns 5):
C#
int ndays = Weekdays(new DateTime(2009, 11, 30), new DateTime(2009, 12, 4));
   System.Console.WriteLine(ndays);

   // leap year test
   ndays = Weekdays(new DateTime(2000, 2,27), new DateTime(2000, 3, 5));
   System.Console.WriteLine(ndays);

   // non leap year test
   ndays = Weekdays(new DateTime(2007, 2, 25), new DateTime(2007, 3, 4));
   System.Console.WriteLine(ndays);
 
Share this answer
 
Comments
Maciej Los 24-May-12 12:23pm    
Good answer, my 5!
Prasad_Kulkarni 24-May-12 23:41pm    
Thank you Isomac!
This should work fine for you
DateTime date = DateTime.Now;
long dateAsLong = date.ToFileTime();
DateTime orgDate = DateTime.FromFileTime(dateAsLong);


Or

DateTime mydate = new DateTime( 1970, 1, 1, 0, 0, 0, 0 );
long mL64 = mydate.Ticks;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900