473,382 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Odd date.tostring problem

Hi,

I need to write todays date incremented by one month as part of a string for
a licence but i'm getting odd results as the tostring function is extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks

Jun 27 '08 #1
5 855
I thought i'd fixed it but no

I changed the declaration to

Dim dTrialExpiryDate As Date = Date.Now.AddMonths(1)

This gives 13/07/2008 14:02:46 (i expected 13/07/2008) and the tostring call
gives 02/13/2008

Now i'm really confused...

"MartinTeefy" wrote:
Hi,

I need to write todays date incremented by one month as part of a string for
a licence but i'm getting odd results as the tostring function is extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks
Jun 27 '08 #2
On Jun 13, 8:01 am, MartinTeefy
<MartinTe...@discussions.microsoft.comwrote:
sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")
but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???
Your format string is incorrect. You are using ToString("mm/dd/yyyy")
when you should be using ToString("MM/dd/yyyy"). Lower case mm gives
you minutes, while upper case MM gives you the month.

Chris
Jun 27 '08 #3
MartinTeefy wrote:
Hi,

I need to write todays date incremented by one month as part of a string for
a licence but i'm getting odd results as the tostring function is extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks
That's not odd at all. The "mm" part of the format string doesn't stand
for months, it stands for minutes.

Use "MM/dd/yyyy".

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #4
Hi Martin,

Some people gives us always a smile, but don't bother, I think we all have
gone once in this trap.

:-)

Cor

"MartinTeefy" <Ma*********@discussions.microsoft.comschreef in bericht
news:E5**********************************@microsof t.com...
Hi,

I need to write todays date incremented by one month as part of a string
for
a licence but i'm getting odd results as the tostring function is
extracting
the middle data section of the datetime variable:

Dim dTrialExpiryDate As DateTime = DateTime.Now.AddMonths(1)

This give the value 13/07/2008 13:52:05

I now want to change this value to 07/13/2008

sTrialExpiryString = dTrialExpiryDate.ToString("mm/dd/yyyy")

but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
middle section of the datetime variable???

Any ideas
Thanks
Jun 27 '08 #5
Cor Ligthert[MVP] wrote:
Hi Martin,

Some people gives us always a smile, but don't bother, I think we all
have gone once in this trap.

:-)

Cor
Just once? :)
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Harag | last post by:
Hi all I think this is in the wrong group but since I don't read others much or code in java script I was wondering if anyone could help me with this small problem, as I code mostly in ASP...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
5
by: darrel | last post by:
I have the following right now to enter a date into SQL getting the data from some pull down menus: ------------------------------------------------- dim dateCCJApprovedDate as DateTime if...
1
by: harsha reddy | last post by:
Dear All, I have a front end form which has a couple of dropdown menus which select data from the database based on the value selected, the stored procedure which the program accesses outputs...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
2
by: Lars Erik Nes | last post by:
Hi all. I have a problem. I get all my data from a dataset (not mssql) and in that dataset i have a table called "Activity". In this table i have a few date fields. When i display the dataset...
2
by: archana | last post by:
Hi all, I am facing some wired problem while using above mention data type. What i am doing is i am writing DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +...
2
by: jereviscious | last post by:
Hi all - Last resort time. I'm importing data from a spreadsheet that I receive from one of my vendor using interop.excel. The date field in excel is entered as 4/7/2006, but when I retrieve...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
5
by: =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?= | last post by:
Hello, I'm facing a strange problem. We have an Asp.net 2.0 Web Application and somehow the date format is changing from one client to another even if all the code is running server-side... ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.