Posts

Get current week number from Date C#

  How can I get the current week number from the date using C# (dot net core)? Imports: using System ; using System . Collections . Generic ; using System . Linq ; Solution #1:  Considering Sunday as the first day of the week. public   static   int   GetCurrentWeek ( DateTime   dt ) { // Sunday as first day of week   DateTime   firstOfMonth  =  new   DateTime ( dt . Year ,  dt . Month ,  1 );   return  (( dt . Day  -  1  + ( int ) firstOfMonth . DayOfWeek )) /  7  +  1 ; } Solution #2:  Considering Monday as the first day of the week. public static int GetCurrentWeek ( DateTime dt ) {   // Monday as first day of week   DateTime firstOfMonth = new DateTime ( dt . Year , dt . Month , 1 );   int dayOfWeek = ( int )( firstOfMonth . DayOfWeek ) - 1 ;   if ( dayOfWeek < 0 ) dayOfWeek = 6 ;   return ( dt . Day - 1 + dayOfWeek ) / 7 + 1 ; } Method Usage: Console . WriteLine ( GetCurrentWeek ( new DateTime ( 2022 , 06 , 27 )));

Get the number of weeks in a month C#

 How can I get the number of weeks in a month using C# (dot net core)? Solution: Considering Sunday as the first day of the week. Imports: using System ; using System . Collections . Generic ; using System . Linq ; Method: public static int GetTotalWeeksInMonth ( DateTime dt ) { //extract the month int daysInMonth = DateTime . DaysInMonth ( dt . Year , dt . Month ); DateTime firstOfMonth = new DateTime ( dt . Year , dt . Month , 1 ); //days of week starts by default as Sunday = 0 int firstDayOfMonth = ( int ) firstOfMonth . DayOfWeek ; int weeksInMonth = ( int ) Math . Ceiling (( firstDayOfMonth + daysInMonth ) / 7.0 ); return weeksInMonth ; }

All git commands you need — get rid of merge conflicts

Image
 Git is a very popular tool for managing codes across small and large teams. GitHub, GitLab, and BitBucket are popular sites where teams generally host their git repositories. With git, you can efficiently work in teams compared to conventional code uploading methods such as FTP. You can create multiple branches for managing codes e.g. production branch, development branch, staging branch, or feature changes branch. With proper knowledge and commands, you don’t need to worry about taking backups of your codes. You can revert to a previous commit state or merge your code with other developers’ codes in your own branch and re-merge your branch into an original branch with the following commands.   Clone repository:   git clone <repo_url>   Clone branch:   git clone -b <branch> <repo_url>   Create a new branch:   git checkout -b <branch>   Switch to an existing branch:   git checkout <branch>   Delete branch locally:   git branch -d <branch>   Delete br

Ask a Question

Name

Email *

Message *