0

I am looking to enter a random date for a given class in a note when passing a note of a block of text. How does one input and add a random date for a given note text?


using CY.Data.Interface;
using CY.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CY.Data.Ado
{
  public class NoteRepository : INoteRepository
  {

.....


    public static void RandomDate()
    {

      // 1. Adding the Start Date for the number of time that it is going to start. 
      // 2. Adding the End Date for the time it is going to end. 
      // 3. Adding the range of the time for the total number of days. 
      // 4. Add a int randDays where one converts the rnd.Next to in a Int32 numRange format. 
      // 5. Print a Random Random on a console writeline input. 
      DateTime startDate = DateTime.Now.AddYears(-1);
      DateTime endDate = DateTime.Now;
      double numRange = (endDate - startDate).TotalDays;
      int randDays = rnd.Next(Convert.ToInt32(numRange));
      DateTime randDate = startDate.AddDays(randDays);
      Console.WriteLine(randDate.ToString());
            }
     }
}

The end result should be utilizing a random Date and running it on the browser. How does use ADO.NET to integrate printing a random date on a given note?

References:
1) Microsoft Documentation on ADO.NET: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-overview

2) Microsoft Documentation on Using Data sets from ADO.NET to print data: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-datasets

Caleb Yang
  • 83
  • 1
  • 12
  • Attached is the missing line of code. ```C# Random rnd = new Random(DateTime.Now.Millisecond); int randDays = rnd.Next(Convert.ToInt32(numRange)); ``` This makes rnd a random type so that it can convert random date to an integer in the menu loop in c#. – Caleb Yang Oct 06 '19 at 16:51
  • 1
    To generate a random date https://stackoverflow.com/a/194870/8367626 What does this have to do with Ado.net? Are you inserting this data in a database (an unknown database) what is the datatype of the date column? – Mary Oct 07 '19 at 01:33

0 Answers0