[dba-VB] VB.Net Date/time in specific format

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Wed May 7 06:53:15 CDT 2008


Hi John,

Please make correction to your string formatting:

Dim dt as String = string.Format("{0:yyyyMMdd_HHmmss}", DateTime.Now)
Console.WriteLine(dt)   

IOW, use uppercase 'HH' instead of lowercase 'hh' - the latter gives the
hour value in 00 - 11 range, and you might get file names collisions: yes,
very low probability to get such collisions but "Murphy Laws" are waiting
us, developers, around every corner, you know, and we have to be very
accurate, and a little bit "paranoid"...

Thanks.

--
Shamil

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Monday, May 05, 2008 7:59 PM
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] VB.Net Date/time in specific format

Thanks, worked perfectly.

John W. Colby
www.ColbyConsulting.com


Shamil Salakhetdinov wrote:
> Hi John,
> 
> This should be it:
> 
> Dim dt as String = string.Format("{0:yyyyMMdd-hhmmss}", DateTime.Now)
> Console.WriteLine(dt)   
> 
> --
> Shamil
> 
> -----Original Message-----
> From: dba-vb-bounces at databaseadvisors.com
> [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
> Sent: Monday, May 05, 2008 7:23 PM
> To: VBA
> Subject: [dba-VB] VB.Net Date/time in specific format
> 
> I need to get the current date / time in a format that does not include 
> : or /, IOW "20030123-082347".  I need it in this format for appending 
> to a file name so that the name is unique and sorts in the directory.
> 
> Has anyone already done this, or know how it is done?  I can get the 
> year part etc., but I am not finding hour, minute or second, and I am 
> just wondering if someone has code already built.
> 
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com




More information about the dba-VB mailing list