How to store & retrieve dates from MS access databse

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

How to store & retrieve dates from MS access databse

 
0
  #1
Aug 9th, 2007
Hi All,

I want to store Student Name & Birth date in the database. How should I store it into database so that I can retrieve it back evenif the system date format is changed(It should retrieve record for dd/MM/yyyy date format also i.e. not only for default date formats). Any clue?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: How to store & retrieve dates from MS access databse

 
0
  #2
Aug 9th, 2007
Hi,

It is always a Good Idea to store Dates in "Julian" style which is Numeric Long type. If stored in this way, whatever be the Local Regional setting of the computer u can get it back to required format. while storing use:

RST("DateField") = CLng(CDate(txtDate.Text))

To Retrieve Back use:

txtDate.Text = Format(RST("DateField"),"dd/MMM/yyyy")

But this has got its own draw back, Reporting gets difficult, in db all the records look like numbers. If using CR, u can create formula to convert it back to date...


Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #3
Aug 10th, 2007
Thanks Veena. I'll try.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #4
Aug 10th, 2007
It works fine. Is it possible to store Time also in the same filed i.e. Birth date & time in one database field using "Julian" style.
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #5
Aug 11th, 2007
I got it. I have used CDbl instead of CLng.

RST("DateField") = CDbl(CDate(txtDate.Text))

Thanks for valuable information.
Last edited by kshrini; Aug 11th, 2007 at 7:39 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: How to store & retrieve dates from MS access databse

 
0
  #6
Aug 12th, 2007
Hi,

Yes u cand do it. Julian Date Represents both date and Time, The Integral part (or the floor) is Date and the Decimal part is the Time, Precising up to 1 MilliSecond.
And u can do with a CDbl. U had asked for date, so i told u to use Long.

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #7
Aug 13th, 2007
Hi,

Thanks a lot!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #8
Aug 13th, 2007
Hi,

New problem. I'm unable to search date in database. In MS Access I've tried by creating query :

SELECT * FROM Results WHERE SettingsID=7 AND TestDateTime=39303.5539930556

This query doesn't return a row, but it is there in the table.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: How to store & retrieve dates from MS access databse

 
0
  #9
Aug 13th, 2007
Hi,

In Database if u have used double to store the record, precision wud have formatted to 4 places. so use this :

SELECT * FROM Results WHERE SettingsID=7 AND TestDateTime=39303.5540




REgards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 44
Reputation: kshrini is an unknown quantity at this point 
Solved Threads: 3
kshrini kshrini is offline Offline
Light Poster

Re: How to store & retrieve dates from MS access databse

 
0
  #10
Aug 13th, 2007
Hi,

In database TestDateTime field has Auto decimal places.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC