Friends please help me in FORMATTING DATE

I have a Form with three text boxes
1.txtNo- Data type-Number
2.txtName-Data type-Text
3.txtDob-Data type -Date format dd/MM/yyyy
two buttons one for adding and the other for viewing
Using visual data manager I have created a database-Members with table-List having the following Fields
Mno -type-integer
Name-type-text
Dob-type -date/time
I added 2 records, in first record the Dob is 18/05/1952 (dd/MM/yyyy format)
in the second Dob is 05/11/1955 (dd/MM/yyyy format)
When we view the first record the Dob is displayed as 5/18/1952 (M/dd/yyyy format)
In the second one Dob is displayed as 5/11/1955 (d/MM/yyyy format)
Why this difference ?I want always the Dob displayed in dd/MM/yyyy format
When the date is =<12 the display is almost correct, But when the date is above 12 the date portion is shifted to month portion and month to date portion

How can I overcome this? Please help me . I want always the date in dd/MM/yyyy format

Dani AI

Generated

Short answer: this is almost always a locale/ parsing issue, not a bug in VB. Dates were being interpreted or displayed with a different culture (MM/dd) than the one you typed (dd/MM). That makes entries where the day is 12 or less look “okay” by accident, while values >12 reveal the swap.

What to check and do (practical checklist)

  • Confirm the table column is really a Date/Time type, not Text. If it's Text you must convert and re-save as Date values.
  • Stop sending dates to the database as concatenated strings. Send real Date values (parameters or recordset field values) so the provider never has to guess the order.
  • Keep formatting strictly in the presentation layer: format the Date when you show it in the UI. Formatting does not change the stored value.
  • If you must build literals, use parameterized commands, or use an unambiguous approach and backup first.

Concrete examples (apply as appropriate)

VB6 (ADO) — use a parameterized command and pass a Date value instead of concatenating text:

' create parameters and pass a Date variable (DobValue) as the adDate parameter
cmd.CommandText = "INSERT INTO List (Mno, Name, Dob) VALUES (?, ?, ?)"
cmd.Parameters.Append cmd.CreateParameter("pDob", adDate, adParamInput, , DobValue)
cmd.Execute

VB.NET — format for display using an explicit culture (UK) instead of relying on system defaults:

' uses en-GB short date formatting for display
TextBoxDob.Text = myDate.ToString("d", System.Globalization.CultureInfo.GetCultureInfo("en-GB"))

Fixing already-bad rows

  • Backup the database first.
  • If dates were actually stored with day/month swapped, you can swap them back in Access with DateSerial. Example (test on a copy):
    UPDATE List
    SET Dob = DateSerial(Year([Dob]), Day([Dob]), Month([Dob]))
    WHERE Day([Dob]) <= 12;  -- pick condition that matches your corrupted rows

    Always test the WHERE clause on a copy to avoid corrupting good dates.

Notes tied to earlier posts

  • and were right that formatting can make a date appear as dd/MM; that helps presentation. The deeper fix is ensuring dates are stored and transported as Date values so parsing can never flip day and month.

Recommended Answers

All 5 Replies

somebody please help me. please.... please.......

use

Print Format$(your_date, "dd/mm/yyyy")

where your_date is the date in any format

I am confused Wher and how to put this code

My code is this

    TxtTdate = Format$(Date, "dd/MMM/yyyy")

This works well as 16/Nov/2013
But I want always as dd/mm/yyyy 16/11/2013

If I change the code like this

    TxtTdate = Format$(Date, "dd/MM/yyyy")

Then the problem begins

firstly , i don't see any problem in the code.

But I want always as dd/mm/yyyy 16/11/2013

Try This:

Format(Now, "dd/mm/yyyy")

Above statement will display present date.So you can also print desired in the Specific Pattern by replacing Now with your date type variable.

the above statement will result in what you want.(16/11/2013).

hope this helps you.

ok thank u , Now I found out my mistakes,it works as I wish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.