error CS0176: Member 'DateTime.Now' cannot be accessed with an instance reference; qualify it with a

Hi, i'm a beginner and i come from JavaScript and python. I'm having an issue with my CSharp code:
using System;
using System.Net; //required
using System.Net.Sockets; //required
namespace Server
{
public class print
{

public void errlog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] ERR: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
public void infolog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] INFO: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
}

class Server
{
private String hostip = "0.0.0.0";
private int hostport = 8713;
static void Main(string[] args){
print.errlog("Hello! This is an error!");
print.infolog("Hello! This is a debug log!");
}
}
}
using System;
using System.Net; //required
using System.Net.Sockets; //required
namespace Server
{
public class print
{

public void errlog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] ERR: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
public void infolog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] INFO: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
}

class Server
{
private String hostip = "0.0.0.0";
private int hostport = 8713;
static void Main(string[] args){
print.errlog("Hello! This is an error!");
print.infolog("Hello! This is a debug log!");
}
}
}
It just errors out: Member 'DateTime.Now' cannot be accessed with an instance reference; qualify it with a type name instead
6 Replies
Doombox
Doombox2y ago
DateTime.Now is now DateTime.Today has no concept of "now"
MODiX
MODiX2y ago
Doombox#1389
REPL Result: Success
Console.WriteLine(DateTime.Now);
Console.WriteLine(DateTime.Today);
Console.WriteLine(DateTime.Now);
Console.WriteLine(DateTime.Today);
Console Output
01/31/2023 15:55:42
01/31/2023 00:00:00
01/31/2023 15:55:42
01/31/2023 00:00:00
Compile: 479.627ms | Execution: 60.829ms | React with ❌ to remove this embed.
Doombox
Doombox2y ago
Today is essentially Now but without the hours/minutes/seconds component
hexlocation
hexlocationOP2y ago
oh ok thanks
Doombox
Doombox2y ago
no worries
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server