© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
43 replies
SWEETPONY

✅ How to sum datetimeoffset and timespan?

I have following structure:
[JsonProperty( PropertyName = "timestamp" )]    
[JsonRequired]                                  
public DateTimeOffset Timestamp { get; set; }   
                                                
[JsonProperty( PropertyName = "ttl" )]          
public TimeSpan? Ttl { get; set; }              
                                                
[JsonProperty( PropertyName = "expires_at" )]   
public DateTime ExpiresAt { get; set; }         
[JsonProperty( PropertyName = "timestamp" )]    
[JsonRequired]                                  
public DateTimeOffset Timestamp { get; set; }   
                                                
[JsonProperty( PropertyName = "ttl" )]          
public TimeSpan? Ttl { get; set; }              
                                                
[JsonProperty( PropertyName = "expires_at" )]   
public DateTime ExpiresAt { get; set; }         

I would like to get expiration time by sum timestamp and ttl

I tried this:
[JsonProperty( PropertyName = "expires_at" )]
    public DateTime ExpiresAt => Ttl.HasValue
        ? DateTime.Now.Add( Ttl.Value )
        : DateTime.MaxValue;
[JsonProperty( PropertyName = "expires_at" )]
    public DateTime ExpiresAt => Ttl.HasValue
        ? DateTime.Now.Add( Ttl.Value )
        : DateTime.MaxValue;

but it's not correct
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Mongo DBDriver, how to serialise DateTimeOffset
C#CC# / help
4y ago
✅ Converting string to DateTimeOffset
C#CC# / help
2y ago
Parsing string to TimeSpan
C#CC# / help
4y ago
DateTimeOffset vs DateTime
C#CC# / help
3y ago