Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2010, 02:31 AM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Date format

I have a access database,data type are "TEXT" for all fields
When i update the database date field appears as 2010-10-22. I want to load it as 10/22/2010. Please advise me what is wrong with my code

Code:
 mydate = CalScheduler.SelectionStart()	 'Date selected on month Calander
       
       
        txtDay.Text = mydate.DayOfWeek.ToString	 'extracting the day of week from the date
       
     

        txDate.Text =    mydate.ToShortDateString()
        
        
   	 Try
            newrow = DsDateExt1.tblDate.NewRow
            'Schedule.newrow = newrow
            newrow("SchDate") = CStr(txtDate.Text)
            newrow("SchTime") = CStr(txtTime.Text)
            newrow("JobType") = CStr(txtType.Text)
            newrow("CustomerID") = CStr(txtID.Text)
            newrow("Comments") = CStr(txtRemarks.Text)           

           
                DsDate1.tblDate.Rows.Add(newrow)
                daDate.Update(DsDate11)

i did try to format date using this code
Code:
Dim theDate As DateTime = txtDate.Text
        Dim ymd As String = theDate.ToString("MM/dd/yyyy")
and then replacingthe txtdate.text to ymd in row update code
newrow("SchDate") = CStr(txtDate.Text)

but result is same. It appears in table as 2010-10-22. The real question here is not the date format but what is happening while updating the table in data base

Last edited by VbStudent9; October 23rd, 2010 at 06:48 PM.. Reason: more info and correction
 
Old October 24th, 2010, 02:15 PM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

First question, why is a date field being defined as Text in Access?

The second thing is I don't think there is a need to convert txtDate.Text to a string since it already is, so strip out all the CStr() functions and try that.

Malc.
 
Old October 24th, 2010, 06:48 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

You are right but it dont make no difference. I tried both with and without cstr for text box but the table value is stored as yyyy-mm-dd. I know textbox values are string values.
The problem with this format is when I search a record for mm/dd/yyyyy it doesnt find. When I search for yyyy-mm-dd it finds the record. when I load datagrid it loads the date as yyyy-mm-dd.

This format is not popular in US. I am thinking ahead. What if i have to do something down the road for a customer and customer doesnt like the format.

If I dont understand what or why this is happening, I may have some serious problem in future.

I will greatly appreciate if some one tells me why or what is happening and what to do to prevent it.

I was using text in access database because I read some where, handling date as string is easier then handling them as date

Last edited by VbStudent9; October 24th, 2010 at 06:51 PM..
 
Old October 24th, 2010, 10:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Well, access is handling dates as the OS format is telling it..

You are getting the date from a calendar, so in your case the calendar is returning the date in the format that is spected by the OS. When you convert it to string, it doesn't matter since the short string from the date is still handle by OS. If you change it in the OS it will also change in the calendar control and probably on the database also.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old November 3rd, 2010, 01:04 AM
Authorized User
 
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default date time issues

I am no expert but a little 2 cent worth
"no matter how the date/time was formatted in the database product, itself, that format is completely lost when the value only is retrieved into ADO and VBScript.

may be this is what happening.
__________________
yvk





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert date to JDEdwards date format snufse ASP.NET 2.0 Basics 1 March 24th, 2009 08:54 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.