473,770 Members | 6,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to format a date to look like 2006-04-16T19:45:42Z


Hi,

I wish to create a string from the current date now() so that it looks
like
the format used by Excel, for instance:

2006-04-16T19:45:42Z

How would I achieve that?

Thank you,

-Pam

PS
Btw does that format has a name?

Apr 25 '07 #1
3 1599
Hello,
2006-04-16T19:45:42Z
It's the ISO8601-based format.

System.DateTime .Now.ToString(" s"); is a good start.

(H) Serge
Apr 25 '07 #2
I wish to create a string from the current date now() so that it looks
like
the format used by Excel, for instance:

2006-04-16T19:45:42Z
That is ISO 8601 Format. It indicates a UTC (Coordinated Unitversal Time)
time, which is the DateTime at 0 degrees longitude (Greenwhich Mean Time -
TMT). So, in order to format your DateTime value properly, you must first
convert it to UTC time, using the DateTime.ToUniv ersalTime() method, and
then call the DateTime.ToStri ng(string format) overload, passing in the
following Custom DateTime string:

"yyyy'-'MM'-'dd'T'HH':'mm': 'ss'Z'"

Unfortunately, the CLR includes Standard DateTime strings that come close,
but not exactly. The closest is "U" which translates to UTC time format
without the "T" before the hh:mm:ss portion.

Example:

DateTime.Now.To UniversalTime() .ToString("yyyy '-'MM'-'dd'T'HH':'mm': 'ss'Z'")

Note that the time is translated to GMT time by default with the assumption
that it is local time. Otherwise, you need to convert the Time to local
first. You can read more about this subject here:

http://msdn2.microsoft.com/en-us/lib....datetime.aspx

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"pamela fluente" <pa***********@ libero.itwrote in message
news:11******** *************@b 40g2000prd.goog legroups.com...
>
Hi,

I wish to create a string from the current date now() so that it looks
like
the format used by Excel, for instance:

2006-04-16T19:45:42Z

How would I achieve that?

Thank you,

-Pam

PS
Btw does that format has a name?

Apr 25 '07 #3
On 25 Apr, 19:32, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
I wish to create a string from the current date now() so that it looks
like
the format used by Excel, for instance:
2006-04-16T19:45:42Z

That is ISO 8601 Format. It indicates a UTC (Coordinated Unitversal Time)
time, which is the DateTime at 0 degrees longitude (Greenwhich Mean Time -
TMT). So, in order to format your DateTime value properly, you must first
convert it to UTC time, using the DateTime.ToUniv ersalTime() method, and
then call the DateTime.ToStri ng(string format) overload, passing in the
following Custom DateTime string:

"yyyy'-'MM'-'dd'T'HH':'mm': 'ss'Z'"

Unfortunately, the CLR includes Standard DateTime strings that come close,
but not exactly. The closest is "U" which translates to UTC time format
without the "T" before the hh:mm:ss portion.
Thank you very much Kevin and Serge,

I will try that.

Very helpful

Cheers,

-Pam

Apr 26 '07 #4

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

Similar topics

1
3900
by: praba kar | last post by:
Dear All, In Php we can print RFC 2822 formatted date by date('r') with parameter r. Then it will print the below format date. "Thu, 7 Apr 2005 01:46:36 -0300". I want to print same RFC 2822 format in python. Is it possible in python? . If possible kindly mention the function related to print RFC format date
2
5065
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the date object with the date string which the user inputs from a pop up calendar. somewhat like this..........
4
3452
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them to select today. example: var dtToday = Date() if(document.frmSoftware.txtDDate.value == dtToday) { alert("You cannot select same day distributions. Please enter a new
0
3112
by: lsy | last post by:
i wonder how can i order my statement interm of "ORDER BY FORMAT(Date, 'mmmm')" with using this it will order by alphabethical but i want it order by month... i had try "ORDER BY FORMAT(Date, 'mm')" but due to at the begining i have "SELECT FORMAT(Date, 'mmmm')FROM TABLE" my actual statement will look like this "SELECT FORMAT(Date, 'mmmm')AS DateMonth, COUNT(x) AS CounterX FROM Table WHERE FORMAT(Date, 'mmmm') BETWEEN 'January' AND 'August'...
1
5513
by: Keith Chadwick | last post by:
Been trying to use the ms:format-date() in one of my transformations. I have all of the necessary declarations in my xml as in <?xml version="1.0" ?> <data xml:space="default" xmlns:dt="urn:schemas-microsoft-com:datatypes"> myxml... </data>
1
6539
by: G Gerard | last post by:
Hello I am having some problem comparing dates with the SQL statement below MySQL = "SELECT Format(Date, 'yyyy/mmmm/dd') as FROM TblDates WHERE _ Format(Date, 'yyyy/mmmm/dd') = #2006/April/18#" Even though the date 2006/April/18 is in TblDates, it is never found by the
2
79084
by: fniles | last post by:
How do you do Format(Date, "mmddyy") in VB.NET ? Thank you
8
5408
by: libsfan01 | last post by:
how can i use regular expressions to ensure a mysql format date entry in a text field? thanks marc
5
4220
mgpsivan
by: mgpsivan | last post by:
Hi, i have form in Asp.net(2003) in that i've to change the format of the date by the following statement Format(Date.Today, "dd/mm/yyyy") but when i give this code the month part displays as 00 i.e i get the output as the folowing for eg: "18/00/2007" can any one help me in changing the format... Thanks in Advance..... Sivan.G.....
2
4756
omerbutt
by: omerbutt | last post by:
hi i need to store the date in the format date('YmdGis') the problem is that locally it is working perfect but when i go live it stops storing the date in this format , although it does store the date('YmdHis') MYSQL Server version: 5.0.41-community-nt MySQL client version: 5.0.41 Server version: 5.0.91-community
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.