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

  • Home
  • SEARCH
  • 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 458819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:42:37+00:00 2026-05-12T22:42:37+00:00

I have this code: startWeekDate = startWeekDate == null ? DateTimeHelpers.calcMondayDate(DateTime.Now) : DateTimeHelpers.calcMondayDate(startWeekDate.Value); DateTime

  • 0

I have this code:

 startWeekDate = startWeekDate == null ? DateTimeHelpers.calcMondayDate(DateTime.Now) : DateTimeHelpers.calcMondayDate(startWeekDate.Value);
 DateTime endWeekDate = startWeekDate.Value.AddDays(6);

startWeekDate is a parameter that is nullable. This works good, but I want to format it with: String.Format(“{d:0}”, …. ) but when I slap that around it I get error.

Cannot implicitly convert type ‘string’ to ‘System.DateTime?

How shall I fix this problem?

/M

EDIT:

I’m trying to add this to the function instead, since it should always return dateformat without clock, but I get same error there with this code:

    public static DateTime calcMondayDate(DateTime input)
    {
        int delta = DayOfWeek.Monday - input.DayOfWeek;
        DateTime monday = String.Format("{d:0}", input.AddDays(delta));

        return monday;
    }

Cannot implicitly convert type ‘string’ to ‘System.DateTime’

hmm, but input is DateTime, why does it complain about it being string?

  • 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-05-12T22:42:37+00:00Added an answer on May 12, 2026 at 10:42 pm

    You’ve shown the code that doesn’t have a problem, but not the code that does have a problem. Please show the code which doesn’t compile. It sounds like you’re trying to assign a DateTime? variable a string value, e.g.

    startWeekDate = string.Format(...);
    

    That’s definitely not going to work. What would you really want it to do with the formatted value once you’ve got it as a string? Use it where you want a string, not where you want a DateTime?.

    One thing to add – your first line can be expressed more simply:

    startWeekDate = DateTimeHelpers.calcMondayDate(startWeekDate ?? DateTime.Now);
    

    EDIT: Now you’ve posted your code, it’s clear why it’s not working – as suspected, you’re trying to assign a string value to a DateTime variable.

    DateTime values don’t have a format. They’re like numbers – they have a value which isn’t inherently formatted. It’s like 0x10 and 16 are the same number, just written differently.

    Now it sounds like you’re just trying to return the date without the time – which is better done as:

    return input.AddDays(delta).Date;
    

    The Date property returns a DateTime with the same date, but midnight as the time.

    On a side note, it’s a shame that .NET has such a restricted set of date/time types, so that you can’t really represent the idea of a time-less date. I’m trying to fix this situation, but it’ll be a while before it bears fruit…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In the end I decided to just draw "cursor" objects… May 12, 2026 at 11:23 pm
  • Editorial Team
    Editorial Team added an answer See the FAQ How do I compute the difference of… May 12, 2026 at 11:23 pm
  • Editorial Team
    Editorial Team added an answer Any message with "should" in the name is expected to… May 12, 2026 at 11:23 pm

Related Questions

I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.