formatting dates 
Author Message
 formatting dates

Hi,
I'm trying to find the equivalent for the VB6 format function when it comes
to dates.  For example I usually have a log file that is called yymmddhh.txt
and I get the name of the file when the app starts by:

    strFile = format(date,"yymmddhh") & ".txt"

this doesn't work in VB.Net and I've got round it by using this format:

    strDate = Year(Now) & Month(Now) & Microsoft.VisualBasic.Day(Now) &
Hour(Now) & Minute(Now) & ".txt"

As you can see its a bit longer, so am I missing the plot or is that the
only way to replicate the succinct VB6 method.

Appreciate your time.

Steve



Sun, 30 Jan 2005 04:57:13 GMT  
 formatting dates
Dim sTxt As String = String.Format("{0:yymmddhh}.txt", Date.Now)

HTH

--
Corrado Cavalli
UGIdotNET - http://www.ugidotnet.org



Sun, 30 Jan 2005 05:36:54 GMT  
 formatting dates
You should be able to use:

   strFile = Now.ToString("yymmddhh") & ".txt"

Keith

Quote:
>-----Original Message-----
>Hi,
>I'm trying to find the equivalent for the VB6 format

function when it comes
Quote:
>to dates.  For example I usually have a log file that is
called yymmddhh.txt
>and I get the name of the file when the app starts by:

>    strFile = format(date,"yymmddhh") & ".txt"

>this doesn't work in VB.Net and I've got round it by
using this format:

>    strDate = Year(Now) & Month(Now) &

Microsoft.VisualBasic.Day(Now) &
Quote:
>Hour(Now) & Minute(Now) & ".txt"

>As you can see its a bit longer, so am I missing the plot
or is that the
>only way to replicate the succinct VB6 method.

>Appreciate your time.

>Steve

>.



Sun, 30 Jan 2005 05:40:53 GMT  
 formatting dates
Steve,

I've try following code, and it works fine:

textbox1.text = format(now(),"yyyy-MM-dd")

Make sure you use MM for month and not mm (these are minutes)
Also date doesn't exists anymore in .net use now()

Hope this will help you...

Tim.


Quote:
> Hi,
> I'm trying to find the equivalent for the VB6 format function when it
comes
> to dates.  For example I usually have a log file that is called
yymmddhh.txt
> and I get the name of the file when the app starts by:

>     strFile = format(date,"yymmddhh") & ".txt"

> this doesn't work in VB.Net and I've got round it by using this format:

>     strDate = Year(Now) & Month(Now) & Microsoft.VisualBasic.Day(Now) &
> Hour(Now) & Minute(Now) & ".txt"

> As you can see its a bit longer, so am I missing the plot or is that the
> only way to replicate the succinct VB6 method.

> Appreciate your time.

> Steve



Sun, 30 Jan 2005 05:51:50 GMT  
 formatting dates
Thanks Guys,
Yes you were right, I had "mm" instead of "MM", which was causing it not
work correctly.  Thanks for your time.

Steve


Quote:
> Steve,

> I've try following code, and it works fine:

> textbox1.text = format(now(),"yyyy-MM-dd")

> Make sure you use MM for month and not mm (these are minutes)
> Also date doesn't exists anymore in .net use now()

> Hope this will help you...

> Tim.



> > Hi,
> > I'm trying to find the equivalent for the VB6 format function when it
> comes
> > to dates.  For example I usually have a log file that is called
> yymmddhh.txt
> > and I get the name of the file when the app starts by:

> >     strFile = format(date,"yymmddhh") & ".txt"

> > this doesn't work in VB.Net and I've got round it by using this format:

> >     strDate = Year(Now) & Month(Now) & Microsoft.VisualBasic.Day(Now) &
> > Hour(Now) & Minute(Now) & ".txt"

> > As you can see its a bit longer, so am I missing the plot or is that the
> > only way to replicate the succinct VB6 method.

> > Appreciate your time.

> > Steve



Sun, 30 Jan 2005 09:48:05 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. searching a routine to convert date number in normal format date

2. formatting date according to language

3. How to Format Date in Union Query.

4. conditionally format date field in report

5. Basic function help to format date

6. create a table with Format Date and Decimalplaces

7. Access 97 Runtime - Format date expression fails in querys

8. Format Date field in query using VBA

9. Format date in foreign language

10. Formatting Date

11. Need help in formatting dates in textbox

12. Formatting Date in Textbox

 

 
Powered by phpBB® Forum Software