Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8929137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:36:25+00:00 2026-06-15T08:36:25+00:00

This code is a simplified version of what I’m trying to do: string day

  • 0

This code is a simplified version of what I’m trying to do:

string day = Thursday;
DateTime dt = DateTime.Now;

if (day == dt.DayOfWeek)
{
     // start the program
}

I need to read a day of the week value from a database, assign it to a string, then compare the string to dt.DayOfWeek to check if the program should execute.

My error is this: “Operator ‘==’ cannot be applied to operands of type ‘string’ and ‘System.DayOfWeek”

Anyone know how to compare a string to a DateTime.DayOfWeek value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:36:26+00:00Added an answer on June 15, 2026 at 8:36 am

    Easiest is to convert enum to string:

    if (day == dt.DayOfWeek.ToString())...
    

    Notes:

    • if you can change type of day to DayOfWeek enum you can avoid string comparisons (and its related localization/comparison issues).
    • if you have to use string make sure to decide if case is important or not (i.e. should “thursday” be equal to DayOfWeek.Thursday) and use corresponding String.Equals method.
    • consider converting string to enum with Parse as suggested in other answers: ((DayOfWeek)Enum.Parse(typeof(DayOfWeek), day)
    • make sure incoming string is always English – if it could be in other languages you’ll need to look into manually matching value to one provided in CultureInfo.DateTimeFormat.DayNames.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This piece of code is a simplified version of a program I would convert
The following code (this is a simplified version of what I need) does not
This is some code that is behaving peculiarly. This is a simplified version of
This is a (very) simplified version of my iPhone code : @interface x {
This is a simplified partial version of my code to demonstrate the issue: function
This is a simplified and explained version of my code: var ptext=parr.find('div.ptext'); //Text Container
Following code is simplified version of the code that I am trying to optimize.
I have this code (simplified version): const int& function( const int& param ) {
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I am reading On lisp and encountered this code (I simplified it a bit).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.