5 Replies - 1150 Views - Last Post: 12 May 2011 - 11:57 AM Rate Topic: -----

#1 cubensis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 10

Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 07:50 AM

I am writing a forum, users may post comments on this forum. When a user posts a comment the newer comments aren't displayed at the top once there reloaded (they go to the bottom).

I'd like to auto add a date and time to an "date" column within the access database and then order the database via this column. Can this be done? Thanks.

This post has been edited by cubensis: 12 May 2011 - 07:51 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Auto adding date/time to a access database via dataset?

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 431
  • View blog
  • Posts: 1,452
  • Joined: 28-April 09

Re: Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 10:21 AM

does the date column already exist in the database? If so then why not just set the date value to the current date and time when you insert the users comment?

Maybe if you could show what you've tried so far and what you're having trouble with we could help a little bit more.
Was This Post Helpful? 0
  • +
  • -

#3 cubensis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 10

Re: Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 10:47 AM

Hi, thanks for your reply. I dont enter the comments personally so couldn't manually add the date/time. The users leave there comments and i'd like the date/time to be added to a date/time column which is currently in the database.

The stuff i have tried didn't work so that's why i posted here, i was hoping there'd be a setting to allow me to auto add the current date and time in access but there isn't.

I was just hoping ther'd be a chunk of code that when a user presses the "submit comment" button added the current date and time to the third column. I thought it'd be quite a common request and therefore pretty straight forward but maybe it isn't?
Was This Post Helpful? 0
  • +
  • -

#4 cubensis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 10

Re: Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 11:04 AM

So after a bit more experimentation I add a new row to the dataset and insert this line of code on the date column;

dr["Comment_Date"] = DateTime.Today;

This inserts the date but not time (the time is fixed at 12:00 AM) anyone know how to add the time?
Was This Post Helpful? 0
  • +
  • -

#5 cubensis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 10

Re: Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 11:16 AM

It seems i posted a little to early, i have figured it, i used this;

dr["Comment_Date"] = DateTime.Today;
dr["Comment_Date"] = DateTime.UtcNow.AddHours(1);

ASP.NET only gives UtcNow so hours can be added or subtracted. Hope this helps someone in the future!
Was This Post Helpful? 0
  • +
  • -

#6 Siren2011  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-May 11

Re: Auto adding date/time to a access database via dataset?

Posted 12 May 2011 - 11:57 AM

TimeSpan add = new TimeSpan(1, 1, 0, 0);
dr["Comment_Date"] = DateTime.Today;
dr["Comment_Date"] = DateTime.UtcNow.AddHours(add);
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1